Open filtered form with record source set in VBA only.

chrisbo

New member
Local time
Today, 06:01
Joined
Dec 17, 2013
Messages
3
Hope I can make this understandable... :rolleyes:

In my Access adp, when I open a certain form (frmVertebrates), the databinding occurs in the Load event for the form, for various reasons. I have not specified any datasource in the form's design view.

Databinding for frmVertebrates:
Code:
Me.Form.RecordSource = "select * from dbo.vertebrates where catalogID=3"

This works great when just opening the form. However, when opening with a filter from a button on another form it won't work, the form displays all records.

Button code:
Code:
DoCmd.OpenForm frmVertebrates, , , "vertID=123"

Obviously, this makes sense, since the record source is explicitly set in the Load event.

Is there a way to capture the filter "vertID=123" so it can be added to the Form.RecordSource sql?

When breaking in the Load-code and watching the 'form' variable, I can't spot the filter condition anywhere...

/Christian
 
Last edited:
You can pass the variable in the OpenArgs of the openform statement.

You can read the OpenArgs in the on load event, if there is something there... add the where clause in addition.
 
Thanks Namliam, I guess I have to go for that.

Still curious though, where and when does the filtering actually take place when passing a "stLinkCriteria" with DoCmd.OpenForm?
 
Dunno, guess it happens "before" the on open can set the recordsource :/
 
Ok, tested a bit;
Tried to enter "select * from dbo.vertebrates" as recSource in designView and watched the 'form' variable while opening. Then the Form.ServerFilter showed up as "vertID=123". It is empty when the recSource in designView is empty.

Guess the server filter has got to have a recordSource to "hook on" to. If not, it's just lost.
 

Users who are viewing this thread

Back
Top Bottom