How to print a Microsoft Access report from within VB. Also, VB 16-bit. (by Jose Garrick)
Original Author: anonomous (or see description)
Code
Access 2.0 can be controlled using DDE, while Access 7.0 and later can be controlled using OLE Automation. In both cases, you are generally limited to what is available as a DoCmd statement/method. I'll assume for the moment that you'll be using one of the 32-bit versions of Access. You first setup a reference to Access in the VB References dialog box. Access 7.0 will show up as "Microsoft Access for Windows 95" and Access 8.0 will be listed as "Microsoft Access 8.0 Object Library".
Once that's done, you can create object variables in your application based on the Access application. This little snippet will open a database, run a report and close the database.
Dim ac As Access.Application
Set ac = New Access.Application
' put the path to your database in here
ac.OpenCurrentDatabase("c:foofoo.mdb")
' by default, the OpenReport method of the
' DoCmd object will send the report to the printer
ac.DoCmd.OpenReport "MyReport"
' close the database
ac.CloseCurrentDatabase
That's about all it takes. Just remember that you need to design the reports so that they can be run unattended. Watch for query prompts, message boxes, etc., in the report design or the code behind the report.