Macro to Open Report from Another Database

  • Thread starter Thread starter PPCO
  • Start date Start date
P

PPCO

Is it possible to create a macro to open another access database and then to
run a report? Thanks
 
Is it possible to create a macro to open another access database and then to
run a report? Thanks

Simpler to just use code.

First Copy and Paste the below code into a Module in your current
database.

Public Sub OpenExternalReport()
Dim appAccess As Access.Application
' Initialize string to database path.
Const strConPathToSamples = "YourPath\YourFileName.mdb"
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strConPathToSamples
appAccess.DoCmd.OpenReport "ReportName", acViewPreview
Set appAccess = Nothing
End Sub

Change "YourPath\YourFileName.mdb" to your actual database path and
Name.
Change "ReportName" to the actual name of the report you wish to open.

Save the module as mdlExtDbReport

Add a command button to a form.
Display the button's property sheet.
Select the Event's tab.
Click on the Click event line.
On that line, write
[Event Procedure]
Then click on the little button with 3 dots that appears on that line.
When the code window opens, the cursor will be flashing between 2
existing lines of code.
Between those 2 lines, write:
OpenExternalReport

Save the changes.

In Form View, click on the command button and the external report will
open.
 
Back
Top