?
Solved

Printing Access Report from VB?

Posted on 2003-02-27
6
Medium Priority
?
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

752 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