Applying a filter to a form in access

G

Guest

Hi,

I am trying to apply a filter that works automatically when the form is
opened.

So far, i know how to do it manually, by selecting the text in the field i
want to filter by and selecting the 'filter by selection' icon.

However, i have read that in order to do it automatically, i need add a
macro or event procedure to the On Open field in the form properties. What
criteria do i need to put into a new macro in order to do this????

Please help!!!

Kind regards,
Michael Jacques
 
R

Rick Brandt

michael_jacques said:
Hi,

I am trying to apply a filter that works automatically when the form
is opened.

So far, i know how to do it manually, by selecting the text in the
field i want to filter by and selecting the 'filter by selection'
icon.

However, i have read that in order to do it automatically, i need add
a macro or event procedure to the On Open field in the form
properties. What criteria do i need to put into a new macro in order
to do this????

Can't help you with a macro, but in VBA code...

Me.Filter = "[SomeField] = 'SomeText'"
Me.FilterOn = True

If you are not opening the form from the db window then the code that opens
the form can automaticallty set the filter...

DoCmd.OpenForm "FormName",,,"[SomeField] = 'SomeText'"
 
G

Guest

Hi, Michael.

To apply a filter in the OnOpen event procedure, set the Filter and FilterOn
properties. Me.Filter must evaluate to a string value, so it can take
several forms:

For a literal value Me.Filter = "[First] = 'Michael'"
For a string variable Me.Filter = "[First] = " & "'" & strCriteria & "'"
For an integer value Me.Filter = "[ContactID] = 3"
For an integer variable Me.Filter = "[ContactID] = " & intFilter

Once the filter is set, turn on the FilterOn property:

Me.FilterOn = True

Hope that helps.
Sprinks
 

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