Open a report in an external database

A

Alex

Running Access 2007. I have some code in a form in db1 that opens db2
(application.followhyperlink "db2path"), which works fine. In the same code
I need to open a report in db2. I've posted in here a few weeks ago and was
referred to code in the following site
http://www.mvps.org/access/reports/rpt0012.htm. I haven't tried this because
it's very long and complicated. It seems like it should be easier than this.
Does anyone know an easier way, with less complicated code that I can simply
open an external database and a report in that db? Thanks for your help.
 
S

Stuart McCall

Alex said:
Running Access 2007. I have some code in a form in db1 that opens db2
(application.followhyperlink "db2path"), which works fine. In the same
code
I need to open a report in db2. I've posted in here a few weeks ago and
was
referred to code in the following site
http://www.mvps.org/access/reports/rpt0012.htm. I haven't tried this
because
it's very long and complicated. It seems like it should be easier than
this.
Does anyone know an easier way, with less complicated code that I can
simply
open an external database and a report in that db? Thanks for your help.

In the remote db, create an Autoexec macro which opens the report.
 
A

Alex

I know I can do that but there's other people who use the db who won't want
the same report open each time the database opens.
 
A

Alex

I got it:

Sub DisplayExternalReport()
Dim strDB
Dim appAccess As Access.Application
' Initialize string to database path.
strDB = "C:\Docs\LTD.mdb"
' Create new instance of Microsoft Access.
Set appAccess = CreateObject("Access.Application")
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase strDB
' Open report.
'The next code line can easily be changed to
'appAccess.DoCmd.OpenForm "frmForm"
'You can even add a Where statement.
appAccess.DoCmd.OpenReport "rptReport", acViewPreview
appAccess.Visible = True
appAccess.UserControl = True
End Sub
 
S

Stuart McCall

Alex said:
I know I can do that but there's other people who use the db who won't want
the same report open each time the database opens.

Well there are a couple of ways to work around this. One is to create a
macro called say MyMacro which opens the report. Then, when you open the db
via code you can specify the /x command line option (look up command line
options in help). Only thing is, I'm not sure you can include command line
options when launching an app via FollowHyperlink. You may need to use the
Shell statement instead...

Another thing you can try is to create a function (to be called from your
Autoexec macro) to open your report and test the Application.UserControl
property:

If Application.UserControl = False Then
DoCmd.OpenReport ...
End If

UserControl will be false if Access is launched via automation, True if not.
The trouble is I don't know whether launching via FollowHyperlink is
considered to be automation ...
 

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