Link to home
Start Free TrialLog in
Avatar of mercia
mercia

asked on

Printing Access Report from VB?

Can anyone show the the correct way of attaching to a database and then printing one of its reports from within VB 6?  
Avatar of Barca
Barca
Flag of Hong Kong image

u should build a data environment first,

then add a DataReport form, then u can design you form there.
Avatar of Éric Moreau
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
ASKER CERTIFIED SOLUTION
Avatar of QJohnson
QJohnson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mercia
mercia

ASKER

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??
how would call a access macro to run in vb please and send a recordsource to it?
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.