Need help with filtering form code

bgeorge12

New member
Local time
Today, 07:11
Joined
Jun 23, 2011
Messages
5
I have a form that is a data entry form. I have learned how to switch it to a filter form by using the Sort & Filter - Advanced - Filter by form. To simplify this I would like to write code (attached to a button) that will do this feature and upon closing the form it returns to data entry again. The field on the form that I want to search by is [Customer ID]. The form name is [Order Details]. Any help will be appreciated. Thanks
 
This post should not be in Macros - rather Forms. Anyway .....

If CustomerID is an Integer number then:

Code:
Docmd.OpenForm "Your Form",,,"[CustomerID] = " & CustomerID.value

If CustomerID is Text then:
Code:
Docmd.OpenForm "Your Form",,,"[CustomerID] = " & CustomerID.value & ""

If CustomerID is stored in a string variable e.g strCustomer then:
Code:
Docmd.OpenForm "Your Form",,,"[CustomerID] = '" & strCustomer & "'"
 

Users who are viewing this thread

Back
Top Bottom