Filter Code

  • Thread starter Thread starter James
  • Start date Start date
J

James

When I type the code for a command button:

Private Sub SpecificationCmd_Click()
DoCmd.OpenForm "ProductSpec2",, [Supplier Code] = "SW11"
End Sub

to open the form ProductSpec2 filtered for Supplier
Code "SW11" it does not work. I am simply faced with the
form opened but with no filter placed upon it.

What am I doing Wrong?

Is there anyway I can adapt this code to apply a filter on
the "supplier code" field for whatever value happens to be
the current form?

Please, if anyone knows how to this, let me know, it's
driving me crazy!

Regards

James
 
James said:
When I type the code for a command button:

Private Sub SpecificationCmd_Click()
DoCmd.OpenForm "ProductSpec2",, [Supplier Code] = "SW11"
End Sub

to open the form ProductSpec2 filtered for Supplier
Code "SW11" it does not work. I am simply faced with the
form opened but with no filter placed upon it.

What am I doing Wrong?

The entire WHERE clause needs to be in Double Quotes. You can then use single quotes
inside of those for your string delimiter.

DoCmd.OpenForm "ProductSpec2",, "[Supplier Code] = 'SW11'"
 
You are actually use the "wherecondition" argument rather than the "filter"
argument. In this case, you need 3 commas rather than 2. The
"wherecondition" is incorrect as well.

Try:

DoCmd.OpenForm "ProductSpec2", , , "[Supplier Code] = 'SW11'"
 
Back
Top