OpenForm ignores query

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
 
B

BeWyched

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

DoCmd.OpenForm "SERVICES", , "qryGetServices"

Cheers.

BW
 
J

Jim Burke in Novi

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.
 
J

John F.

Thank you very much, Jim. So simple, but so obscure....wish the 'Help'
documentation had told me this....

Best,

johno.
 
J

John F.

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

Best,

johno.
 
D

Douglas J. Steele

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top