Use OLE Automation to Print Access Reports

You can print canned reports in an Access database from VB in different ways. I created this routine to print any report with any criteria or filter from any database. It opens Access with the user- or program-controlled database, then opens the report in the mode specified. In order for this to work with Access constants, you must select Access from the References dialog box (accessed from References under the Tools menu in VB4 and under the Project menu in VB5).

The PrintReport subroutine has the same parameters as the Access Docmd.OpenReport command with the exception of DBPath. I didn’t use IsMissing to test for missing parameters because Access handles it for you, but you can add it to supply your own default values for any missing parameters. Note: In VB4, any optional parameter must be a Variant data type. When you want to print a report from code, call the routine like this:

 	PrintReport MyDBPath, MyReportName, acPreview, _		MyCriteriaSub PrintReport(ByVal DBPath As String, ByVal ReportName _	As StringOptional OpenMode As Integer, Optional Filter As String, _	OptionalCriteria As String)	Dim appAccess As Object	Set appAccess = CreateObject("Access.Application")	appAccess.OpenCurrentDatabase (DBPath)'********************************************************	'Access constants for OpenMode are	'acNormal  - Print (default)	'acPreview - Print Preview	'acDesign  - Design Edit Mode    '********************************************************	appAccess.DoCmd.OpenReport ReportName, OpenMode, _		FilterNameCriteria'********************************************************	'if open mode is Preview then don't quit Access this can	'also be deleted if you do not want Access to quit after	'printing a report'********************************************************	If OpenMode <> acPreview Then		appAccess.Quit	End If	Set appAccess = NothingEnd Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS