Running a Macro from VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using a combo box to select a company name from a table, then using that name to select the company detail from a query. This Query is then the basis for a report. I have modified the 'Run Query' coding of a command button to open the report, then close the query...which is where my problems start!!!
Dim stDocName As Strin
Dim ReportName As Strin

ReportName = "Equipment_Manufacturer Query
stDocName = "Equipment_Manufacturer Query

DoCmd.OpenQuery stDocName, acNormal, acEdi
DoCmd.OpenReport ReportName, acViewPrevie
DoCmd.RunMacro CloseQuery.CloseQuery, 0,
The macro 'CloseQuery' is part of a group. I keep getting "Object Required" as a pop-up?????why..
My experience of vba is....well....about -10 on the scale
 
It should not be necessary to open the query first. Just OpenReport. (I
suspect the report would open its own instance of the query, so having it
already open would not help.)

RunMacro requires you to supply the name of the macro, which needs to be in
quotes, e.g.:
DoCmd.RunMacro "SomeMacro.CloseQuery", ...
Depending on what is in your macro, you may need to SelectObject first.

Or you could forget the macro and code:
DoCmd.Close acQuery, strDocName

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Colin said:
I am using a combo box to select a company name from a table, then using
that name to select the company detail from a query. This Query is then the
basis for a report. I have modified the 'Run Query' coding of a command
button to open the report, then close the query...which is where my problems
start!!!!
Dim stDocName As String
Dim ReportName As String

ReportName = "Equipment_Manufacturer Query"
stDocName = "Equipment_Manufacturer Query"

DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.OpenReport ReportName, acViewPreview
DoCmd.RunMacro CloseQuery.CloseQuery, 0, 0
The macro 'CloseQuery' is part of a group. I keep getting "Object
Required" as a pop-up?????why...
 
Back
Top