OpenForm ignores query

  • Thread starter Thread starter John F.
  • Start date Start date
J

John F.

Hi:

I have a button (btnAddServices) on a form which opens a linked form
("SERVICES") using 'OpenForm':

Private Sub btnAddServices_Click()
DoCmd.OpenForm "SERVICES", , qryGetServices
End Sub

The qryGetServices has 2 parameters which the user is supposed to enter (if
I open the query on its own, it requests the parameters and opens the
correct, limited number of records). At no time does the program ask for
these pramaters when the button is clicked; instead it opens 'SERVICES'
showing all records.

Why does it ignore the query?

Thank you.

johno
 
The query should be within "s. i.e.:

DoCmd.OpenForm "SERVICES", , "qryGetServices"

Cheers.

BW
 
What BeWyched said. Because you don't have it in quotes, VBA thinks it's a
variable called qryGetServices, which would have a value of NULL since it was
never assigned a value.
 
Thank you very much, Jim. So simple, but so obscure....wish the 'Help'
documentation had told me this....

Best,

johno.
 
Thank you, BeWyched: So simple, but so obscure....wish the 'Help'
documentation had told me this....

Best,

johno.
 
Don't know what help documentation you were reading, but, for instance,
http://msdn.microsoft.com/en-us/library/aa220276(office.11).aspx shows that
the syntax is

expression.OpenForm(FormName, View, FilterName, WhereCondition, DataMode,
WindowMode, OpenArgs)

and states that FilterName (the third parameter) is "A string expression
that's the valid name of a query in the current database." "String
expression" means that it either needs to be "qryGetServices" (i.e.: in
quotes), or a string variable that contains the value qryGetServices.
 
Back
Top