Open a query window from a VBA sub triggered from a form

R

Roger Withnell

I'm using the following code to run a SELECT query:

Private Sub cmdSelectQuery_Click()
Dim strSQL As String
Dim qd As DAO.QueryDef
Dim db As DAO.Database
Set db = CurrentDb
Set qd = db.QueryDefs("Complaints Query")
strSQL = "SELECT Ingredients.Ingredient, " & txtSelectComplaint & " FROM
Ingredients"
strSQL = strSQL & " LEFT OUTER JOIN Complaints ON"
strSQL = strSQL & " (Ingredients.Ingredient = Complaints.Ingredient)"
strSQL = strSQL & " WHERE " & txtSelectComplaint & " IS NOT NULL"
strSQL = strSQL & " ORDER BY Ingredients.Ingredient"
qd.SQL = strSQL
Set qd = Nothing
Set db = Nothing
End Sub

How do I make this sub open the query window so that I can see the result,
without having to open the query window manually?
 
R

Roger Withnell

Many thanks.

But how do I close the query window? Or, better still, how do I refresh it
after running the sub?

I've just got into this programming Office. I think I'm getting the idea in
principle, but where do I find a reference that allows me to find these
answers, rather than taking your time?
 
A

Arvin Meyer [MVP]

Roger Withnell said:
Many thanks.

But how do I close the query window? Or, better still, how do I refresh it
after running the sub?

Normally. no one looks at the results of a query in the query window. We put
those results into a form or report. Forms can be requeried, and reports can
be run multiple times.
I've just got into this programming Office. I think I'm getting the idea in
principle, but where do I find a reference that allows me to find these
answers, rather than taking your time?

There are a number of good books on programming in Office. The best I've
found have been written by Ken Getz (et. al.) and F. Scott Barker. I also
like books written by John L. Viescas. Your best bet for fast answers though
is here. There are dozens of knowledgeable folks who enjoy answering
questions.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 

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