Running a query

  • Thread starter Thread starter Tony Williams
  • Start date Start date
T

Tony Williams

I have a form that has a command button that runs a macro. The macro runs
the preview of a report. However I want a query to run before the report is
created which will update fields in my table. How can I do this with one
command button? The macro only has a choice to open the query not run it.
There is a choice to run sql code but my sql statement is too long for the
macro limit.
Thanks
Tony
 
Using the OpenQuery action in a Macro will run an Action query. If
SetWarnings is on, then you will get the "You Are about to Update 316
records....." message.
 
Tony Williams said:
I have a form that has a command button that runs a macro. The macro runs
the preview of a report. However I want a query to run before the report
is created which will update fields in my table. How can I do this with one
command button? The macro only has a choice to open the query not run it.
There is a choice to run sql code but my sql statement is too long for the
macro limit.
Thanks
Tony

Use some code in the command button's click event (untested):

Dim strSQL As String
strSQL = "Your SQL code"

Docmd.RunSQL strSQL
Docmd.OpenReport "rptMyReport"

Keith.
www.keithwilby.com
 
Convert the Macro to VB code. You can do this by right clicking on your
Macro and choose SaveAs... and in the AS box, choose Module. This will
create a new module in VB code. Then in that code, add whatever you need
before the line that the macro used to execute.

Function MacroPreview()
DoCmd.OpenQuery "MyActionQuery"
DoCmd.OpenReport "MyReport", acPreview
End Function

Naturally, you will use your actual query and report names.

In the Button properties, choose the OnClick event, change it to an Event
Procedure and just put the name of the new function in the event sub. It
will probably look something like this:

Private Sub Command2_Click()
Call MacroPreview
End Sub

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
Back
Top