Open report in another database

D

Dale Fye

I have some reports in another Access database that I want to be able to run
and display from within my current database. This second database is linked
to the same datasource as the first.

So far, I've not been able to come up with anything other than to Shell to
that database, pass it some command line parameters, and add some code to
that db to interpret the parameters and then open the report I want. I've
figured out how to open the db using shell command, but cannot figure out the
correct syntax to pass command line parameters). Basically, I've got:

strProgram = chr$(34) & "C:\Program Files\....\MSAccess.exe " & chr$(34)
strFileName = chr$(34) & " C:\MyProgram.mdb"
strCmdLine = chr$(34) & " cmd/ This is a test" & chr$(34)

Shell(strProgram & strFileName) 'This works to open Access to the specified
mdb

Shell(strProgram & strFileName & strCmdLine)

'This generates an error :The command line you used to start Microsoft
Access contains an option that Microsoft Access doesn't recognize.

Any ideas about how to format strCmdLine to get it to run would be greatly
appreciated.
 
M

Marshall Barton

Dale said:
I have some reports in another Access database that I want to be able to run
and display from within my current database. This second database is linked
to the same datasource as the first.

So far, I've not been able to come up with anything other than to Shell to
that database, pass it some command line parameters, and add some code to
that db to interpret the parameters and then open the report I want. I've
figured out how to open the db using shell command, but cannot figure out the
correct syntax to pass command line parameters). Basically, I've got:

strProgram = chr$(34) & "C:\Program Files\....\MSAccess.exe " & chr$(34)
strFileName = chr$(34) & " C:\MyProgram.mdb"
strCmdLine = chr$(34) & " cmd/ This is a test" & chr$(34)

Shell(strProgram & strFileName) 'This works to open Access to the specified
mdb

Shell(strProgram & strFileName & strCmdLine)

'This generates an error :The command line you used to start Microsoft
Access contains an option that Microsoft Access doesn't recognize.

Any ideas about how to format strCmdLine to get it to run would be greatly
appreciated.


You have the / in the wrong place.
strCmdLine = chr$(34) & " /cmd This is a test" & chr$(34)

A different way to run a report in a different mdb file
(mdb2) is to add that file as a reference. First, create a
Public procedure in a standard module in mdb2 that performs
the OpenReport method for you. Then, with the reference in
place, you can use that procedure when you want to open the
report.
 
D

Dale Fye

Marshall,

Thanks, I knew it had to be something simple, 'cause I tried all the hard
stuff.

I know I can add the reference to the other database, but in this instance,
my main application is running with the Access window hidden. I've found
that even if the report is modal and popup, it will not display on screen
when the Access window is hidden, so I'm trying to work around that by
putting the reports in a separate db, which will open up with the Access
Window maximized, then close the window when the report is done.

I think this should work.

Wish me luck

Dale
 
M

Marshall Barton

Sounds like you've got a good grip on the problem so all I
can say is - Good Luck Dale ;-)
 
D

Dale Fye

Marsh,

Changing the "/" to before "cmd" did the job, and I was able to get my code
to run, but it turns out that if the Access window is hidden for one
instance, it appear to be hidden for all instances.

I worked around this by using OutputTo and sending it to the snapshot
viewer, with AutoStart set to true.

Thanks for your help.

Dale

Marshall Barton said:
Sounds like you've got a good grip on the problem so all I
can say is - Good Luck Dale ;-)
--
Marsh
MVP [MS Access]


Dale said:
Thanks, I knew it had to be something simple, 'cause I tried all the hard
stuff.

I know I can add the reference to the other database, but in this instance,
my main application is running with the Access window hidden. I've found
that even if the report is modal and popup, it will not display on screen
when the Access window is hidden, so I'm trying to work around that by
putting the reports in a separate db, which will open up with the Access
Window maximized, then close the window when the report is done.

Wish me luck
 

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