Running a query from a command button

  • Thread starter Thread starter Rose
  • Start date Start date
R

Rose

It's OpenForm, OpenTable, OpenReport...what on earth is it
to run a query from a command button? Nothing in Object
Browser seems to be it.
FYI, I'm setting up a switchboard for all the different
queries, because they want the numbers in Excel and I'm
having problems getting the totals to 'port to Excel if I
go from a report.
 
It's OpenForm, OpenTable, OpenReport...what on earth is it
to run a query from a command button? Nothing in Object
Browser seems to be it.
FYI, I'm setting up a switchboard for all the different
queries, because they want the numbers in Excel and I'm
having problems getting the totals to 'port to Excel if I
go from a report.

There is an OpenQuery method. The problem is you appear to be using
the built in switchboard created by the Access Switchboard manager
which does not support the OpenQuery method directly.
Create either a macro to open the query, or write a procedure in a
module:
Public Sub RunQuery()
DoCmd.OpenQuery "QueryName"
End Sub

Then, using the Switchboard manager, edit one of the buttons to either
Run Macro or Run Code, writing the name of the Macro or the Procedure
name (RunQuery) where indicated.

A better long range solution would be to scrap this switchboard and
create a new one using an unbound form with command buttons. You'll
have better control over it's functionality and maintenance will be
simpler. If you use the wizard to create the buttons, Access will
write most of the code for you.
 
Back
Top