Reputation: 63
I'm using VBA for Access. I have some forms that I want filter.
With the follow code:
a = "ID =" & idwanted
Form_Form1.Form.Filter = a
Form_Form1.Form.FilterOn = True
It works nice, the form is correctly filtred. But I need to filter by 2 fields, something like that:
a = "ID =" & idwanted
b = "Name =" & namewanted
Form_Form1.Form.Filter = a And b
Form_Form1.Form.FilterOn = True
But it give me a error (non match types), but all the fields and variables (a & b) are integer.
(If I do only with b, it filter it correctly.)
Thanks for read me!
Upvotes: 0
Views: 1793
Reputation: 5809
You can just make sure you use the right data type literal. Also you need to concatenate the two conditions. Finally Name
is a reserved word, so you need to enclose them in []. Something like,
a = "ID =" & idwanted
b = "[Name] = '" & namewanted & "'"
Form_Form1.Form.Filter = a & " And " & b
Form_Form1.Form.FilterOn = True
Upvotes: 1