filter a record on form load??

pablavo

Registered User.
Local time
Today, 11:09
Joined
Jun 28, 2007
Messages
189
Hi

I feel a little silly asking a question that is very simple. however, I can't find much documentation on the net etc. I know how to create a combo box filter with code but I don't know how to create a filter on form load to limit it to one record when the form opens.

That's all i'm trying to do. On the assumption that this will speed things up, if I could have code so that, when the form opens it will already be filtered to one record, say, by the first MainID etc.

I've thought about putting a combobox on the first form that opens the "data" form and using a reference on the dataform record source to the first forms combo. I don't really want to effect any of the search criteria on the dataform.

Does any one know (or can point me to) any code that might do this without effecting the data forms search criteria?

thankyou
 
try on your Form_Load event

Me.Filter = "MainID = 1"
Me.FilterOn = True
 
Hey, thanks for the help Fernando.

I tried it, the only problem was that because old records get archived, whatever ID I put might, at one point, might cause Access to filter nothing.

I tried the RecordsetClone.findfirst, I was a little weary incase it was slower (I'm not really sure if it is)

I ended up using this:

If IsNull(Forms!frmProjectMain!MainID) = False Then
DoCmd.GoToRecord , , acFirst
End If
Me.FilterOn = True


Seems to work just the same.
If you get time, perhaps you can tell me if the code i'm using seems ok.

Thanks again for giving me the Me.FilterOn
 

Users who are viewing this thread

Back
Top Bottom