VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Printing a Microsoft Access Report from Visual Bas

by anonomous (or see description) (1 Submission)
Category: OLE/COM/DCOM/Active-X
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (8 Votes)

How to print a Microsoft Access report from within VB. Also, VB 16-bit. (by Jose Garrick)

Rate Printing a Microsoft Access Report from Visual Bas

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:\foo\foo.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.

Download this snippet    Add to My Saved Code

Printing a Microsoft Access Report from Visual Bas Comments

No comments have been posted about Printing a Microsoft Access Report from Visual Bas. Why not be the first to post a comment about Printing a Microsoft Access Report from Visual Bas.

Post your comment

Subject:
Message:
0/1000 characters