Sub QryReport()
    On Error Resume Next
    
    Dim QryDef As QueryDef
    Dim str As String
    
    Set QryDef = dbase.QueryDefs("balancesheet")
    dbase.QueryDefs.Refresh
    
    If Err.Number = 3265 Then
        Set QryDef = dbase.CreateQueryDef("balancesheet")
        dbase.QueryDefs.Refresh
    End If
    

        str = "select *  from [balancesheet]" & _
              " where Date ='" & Dtpicker.Value & "'"

    QryDef.SQL = str
    datareport1.Show
    End Sub

here show the all data. but the sql command not work. I mean when I select a date the report didn't show that date's data. it show all data. what problem ?

Recommended Answers

All 5 Replies

Try the following syntax -

str = "SELECT *  from [balancesheet] WHERE Date = DateValue(" & "'" & Dtpicker.Value & ")" & "'"

You can also choose a specific date as in -

str = "SELECT *  from [balancesheet] WHERE Date => DateValue(" & "'" & Dtpicker.Value & ")" & "'"

not work. it show the all data.

str = "select * from [balancesheet] where Date ='" & Dtpicker.Value & "'"

Make sure that you refer to 'Date' above as a field in your database. If you have named your date field something different, then use that name syntax i.e. your date field name is 'DateOfRecord' your code will look something like -

str = "SELECT *  from balancesheet WHERE DateOfRecord=DateValue(" & "'" & Dtpicker.Value & ")" & "'"str

Also get rid of the [] tags, it is only used when there is a space in your data table name for instance balance sheet will become [balance sheet].

hope this solves your problem.

not work. more thing:
1. I use query (balancesheet)
2. in dataenvironment: data object - view , object name - balancesheet. in grouping tab - field used grouping - category. in Aggregates tab - name: total, function: sum, Aggregate on: grouping, Field: Amount.
here I do it, to see the sum of category. it work, I mean it show the total sum by category. but the above code i use to see the sum of category by date. I mean I select a date and the total sum will show by this date.

anybody can help me?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.