Use OLE Automation to Print Access Reports

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes