Filter Code not working for date formats

Richard66

Richard
Local time
Today, 08:16
Joined
Aug 20, 2009
Messages
55
:confused:
Hi i have a pop-Up filter form which filters the records on a report.
1 to 5 of the filters work great but the other two 6 to 7 dont work and come back with a error.
I understand that the Error is due because im filtering on Date formats for two of them 6 and 7. Is there anyway to resolve this here is the code below.
Regards Richard

Private Sub Set_Filter_Click()
Dim strSQL As String, intCounter As Integer
'Build SQL String
For intCounter = 1 To 7
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
'Strip Last " And "
strSQL = left(strSQL, (Len(strSQL) - 5))
'Set the Filter property
Reports![QECDLReport].Filter = strSQL
Reports![QECDLReport].FilterOn = True
End If
End Sub

P.S
By the way im sorry i am just new to vba. Thanks all
 
your code is putting " -or Chr(34)- around your parameter, however for dates you must use # instead.
 
Thanks for the reply back to me, i am a bit new to VBA how could i do this for the two boxs that have on my form using and modifying the Code it? sorry.
 
If ... < 6 then
... your current sql
else
... your sql but with # instead of "
Endif
 
Ok Thanks i will have a try and see how i get on. Many thanks for you time.
 
Im Sorry i have tryed to replace the " in the code with # but get a Compile error.
Could you tell me which one i am supposed to changed, as you tell can i am really struggling many thanks Richard.
Else
If Me < Filter6 Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
 
...." = #" & Me("Filter" & intCounter) & "# And "
 
Thanks so much for the reply back.
Cheers for all your help
Richard
 

Users who are viewing this thread

Back
Top Bottom