?
Solved

Printing Access Report from VB?

Posted on 2003-02-27
6
Medium Priority
?
286 Views
Last Modified: 2010-05-01
Can anyone show the the correct way of attaching to a database and then printing one of its reports from within VB 6?  
0
Comment
Question by:mercia
6 Comments
 
LVL 3

Expert Comment

by:Barca
ID: 8035361
u should build a data environment first,

then add a DataReport form, then u can design you form there.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8035817
Const dbPathName = "c:\database.mdb"
Const strPassword = "PASSWORD"
Dim Acc As Object, db As Object

Set Acc = CreateObject("Access.Application")
Set db = Acc.Application.DBEngine.Workspaces(0).OpenDatabase(dbPathName, 0, False, ";pwd=" & strPassword)
Acc.OpenCurrentDatabase dbPathName, False
Set db = Nothing
Acc.DoCmd.OpenReport "ReportName", acPreview
Set Acc = Nothing
0
 
LVL 3

Accepted Solution

by:
QJohnson earned 800 total points
ID: 8035841
If you set a reference to the MS Access Object Library for your appropriate version and start with this:

   Dim appAcc As Access.Application
   Set appAcc = New Access.Application
   
   With mappAcc
     
      .OpenCurrentDatabase "DatabasePathAndName.mdb"
      .DoCmd.OpenReport "TestReport", acViewPreview
     
   End With


Use the object browser to discover how to call other methods and set properties to integrate this into your app.

By the way, you can also just as easily call RunMacro command which can, of course, always run a report and do so much more.  So you have some flexibility in where you build your automation control - some in Access and some in VB6.  As a rule, it's lots easier to control Access from Access.  So whenever I automate Access from VB (which is fairly rare, by the way), I usually distill the Access work down to a macro and then just call it with VB.

Perhaps one of the folks here who automate Office programs in most of their apps can offer some more expansive help.

Q
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:mercia
ID: 8040588
Thank you for this quick solution, it works well I would like the report to be displayed on screen instead of having to toggle to access, any clues??
0
 

Expert Comment

by:FiRe5tOrM
ID: 8954251
how would call a access macro to run in vb please and send a recordsource to it?
0
 
LVL 3

Expert Comment

by:QJohnson
ID: 8954455
You just call the RunMacro method of the Access Application object's DoCmd class:

  Dim appAcc As Access.Application
  Set appAcc = New Access.Application
 
   With mappAcc
     
     .OpenCurrentDatabase "DatabasePathAndName.mdb"
     .DoCmd.RunMacr "myMacroName"    
  End With

The only optional arguments it supports have to do with how many times you want to repeat the call to the macro.  You can't specify a recordsource for a macro - there just isn't any context to do so.

But your macro could run lots of queries for you that BUILD the recordsource you want.  Or you could run the queries yourself from the VB side of your application and then dump the contents of the recordset you have into a table.  The macro could invoke reports or other objects to use the contents of the table.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question