docmd.openform help

Tee2

Registered User.
Local time
Today, 02:51
Joined
May 28, 2015
Messages
23
My code seems to ignore the WHERE condition when it initially opens the form but if I run it a second time with the form already open the filter is applied. Just seeking advice on what property on the form could be blocking this from working properly because in a simplified database I tested this in it worked.

Example:
Code:
 docmd.openform "formname", , , "[ID] = " & sID
Thanks!
 
if you dont want the filter dont use the key,
Code:
if sID ="" then
    docmd.openform "formname"
else
  docmd.openform "formname", , , "[ID] = " & sID
endif
 
When you initially open? Are you opening via a Control Action or are you putting that in the On_Event of the Form? The latter will not work...
 
When you initially open? Are you opening via a Control Action or are you putting that in the On_Event of the Form? The latter will not work...
It is being called from a button on a separate form.

if you dont want the filter dont use the key,
I do want the filter but it is not being applied. I am assuming there is a form property barring it from working because this works on a trial database I tested it on.
 
If you are opening from a button it should work. Check the Form Properties and make sure it's set to Allow Filters.
 
If you are opening from a button it should work. Check the Form Properties and make sure it's set to Allow Filters.

Yep, I checked that already and if they weren't allowed it should block it even on the 2nd attempt. I don't understand why it isn't working but it should work another way by just doing...

Code:
forms("formname").filter = "[ID] = " & sID
forms("formname").filteron = true

Sorry, I should have thought of that before posting but I was stuck on figuring out why that wasn't working! Thanks for your responses.
 
Does that mean it's working? If not, is there any other code behind the Form? If yes, please post...
 
Code:
docmd.openform ("formname")
forms("formname").filter = "[ID] = " & sID
forms("formname").filteron = true

That works but I never figured out why it was ignoring the filter on my original line. Oh well!
 

Users who are viewing this thread

Back
Top Bottom