• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

open a report from different DB

Hi all,
I would like a button on a ADP form should open a report saved in a access MDB file (they happen to be linked to the same DB back end).
please let me know how to accomplish that,
Thanks
0
bfuchs
Asked:
bfuchs
  • 5
  • 3
  • 2
3 Solutions
 
aikimarkCommented:
I would think that you should be able to do the following:
1. instantiate a Access.Application object
2. Open the mdb database
3. Invoke Docmd.OpenReport
0
 
bfuchsAuthor Commented:
hi thanks for replying,
do you have a sample of code that does the above?
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Here's an example:

Dim acc As New Access.Application
acc.OpenCurrentDatabase("Path to your remote database")

acc.DoCmd.OpenReport "YourReportName"
acc.Visible = True

This will open a second instance of Access, and then show your report in that instance of Access.

Or you could import the report into your database, link the needed tables, and then show the report directly. This is often much simpler, and involves far less issues.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
aikimarkCommented:
I usually use late binding.  This version of Scott's code uses late binding.
Dim acc As Object
set acc = createobject("Access.Application")
acc.OpenCurrentDatabase("Path to your remote database")

acc.DoCmd.OpenReport "YourReportName"
acc.Visible = True

Open in new window

================
@bfuchs
Do you need to preview the report or just print the report?
0
 
bfuchsAuthor Commented:
@Scott,
I am getting an error message that its open exclusively by another user (and that is expected).
when i try acc.OpenCurrentDatabase("DBPath",0)
i get an error expected:=
0
 
bfuchsAuthor Commented:
@aikimark
probably need it for both.

also, didn't get what is the difference between scott's code and the one you posted?
0
 
bfuchsAuthor Commented:
actually tested again and works, great job!
Thank you.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
also, didn't get what is the difference between scott's code and the one you posted?
aikimark uses what is known as "Late Binding", whereas mine uses "Early Binding". the different is this:

Dim acc As New Access.Application

vs

Dim acc As Object

In mine (the first) I've actually defined the name of the class/object I will use. This allows me to use Intellisense and such, whereas Late Binding does not.

Late Binding is generally easier to deploy, since it does not require you to have a Reference to your library included with your project, and can work against multiple versions.

That said, since you're automating Access (presumably) from within Access, there's no real gain to be made from Late Binding since you obviously have Access running.
0
 
bfuchsAuthor Commented:
Hi Scott,
Thanks for this detailed info, its a topic that i never had clear understanding of...
Ben
0
 
aikimarkCommented:
Since I usually post code snippets, late binding allows someone to drop it into their project without having to add any references.

Glad this worked for you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now