Filter a report from a Pop-Up Form

G

Guest

I am trying to filter a report dynamically by a pop-up form. Here is the code I use to create the SQL expression.

For intCounter = 1 To 3
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & _
Chr(34) & " And "
End If
Next

If strSQL <> "" Then
strSQL = Left(strSQL, (Len(strSQL) - 5))
Reports![RPT-PNDynamic].Filter = strSQL
Reports![RPT-PNDynamic].FilterOn = True
End If

There is no problem to create the SQL expression but one of the fields I want to filter is a Date/Time type in the Table. So when it goes to apply the SQL expression, I receive the following error message: Data Type mismatch in criteria expression. Access does not want to match the SQL expression (string Type) with the Date/Time Type, which is not a big surprise. How can I get this to work?

I am using Access 97
 
S

SA

Yanik:

When you concantate date/time variables, they must be wrapped in pound signs
as in:

strSQL & "#" & Date/TimeVar & "#"
 
G

Guest

Thank you again, but I have a other question.

What about Currency and Number variables
 
S

SA

Currency and number values can simply be concantated with a simply & value
&, text values must be use an apostrophe quoatation pair as in '" & text
value & "' more string "
 
G

Guest

Merci beaucoup! Very appreciated

----- SA wrote: ----

Currency and number values can simply be concantated with a simply & value
&, text values must be use an apostrophe quoatation pair as in '" & text
value & "' more string
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top