Filter Code "Type Mismatch"?

K

KT

I have two text boxes on a form, [Year] and [Month]; and a button.

I put this code in the Onclick event for the button. I would like to apply
filter to the form with these two boxes.

Data type for both are Number, Field length for Year is Integer, for Month
is Double

When I run the code, I got a "Type mismatch" error.

Am I coding this right?

Thanks!!


Private Sub Command24_Click()

If IsNull((Me.Year) Or (Me.Month)) Then
Me.FilterOn = False
Else
Me.Filter = "[Year] = " & Me.txbYear And Me.Filter = "[Month] = " &
Me.txbMonth
End If

End Sub
 
A

Allen Browne

Try:
Me.Filter = "([Year] = " & Me.txbYear & ") And ([Month] = " &
Me.txbMonth & ")"

BTW, Year and Month are both function names in VBA, so you can strike
problems using them as field names.
 
Top