Stuart McCall's Microsoft Access Pages - Reports

Home

Determine if Report exists in current Database

Public Function IsReport(ReportName As String) As Boolean
    Dim rpt As Access.AccessObject
    
    For Each rpt In CurrentProject.AllReports
        If rpt.Name = ReportName Then
            IsReport = True
            Exit For
        End If
    Next
End Function

Paste this Code into a standard module.

Usage:

Debug.Print IsReport("MyReport")
Home Contents

Print a Report to a chosen Printer

Public Function PrinterList() As String
    Dim pr As Access.Printer
    Dim r$
    
    For Each pr In Application.Printers
        r = r & ";" & pr.DeviceName
    Next
    If r <> "" Then
        PrinterList = Mid$(r, 2)
    End If
End Function

Public Sub SetDevice(ByVal pDevice As String)
    Static SavedPrinter As String
    
    With Application
        If Len(pDevice) Then
            SavedPrinter = .Printer.DeviceName
            Set .Printer = .Printers(pDevice)
        Else
            Set .Printer = .Printers(SavedPrinter)
            SavedPrinter = ""
        End If
    End With
End Sub

Paste this Code into a standard module.

Preparation:

  1. Set the Report to print to the Windows default printer (File | Page Setup | Page | Default Printer).
  2. Provide the user with a listbox from which to choose a printer.
  3. Set the listbox's RowSourceType property to Value List.
  4. Set the listbox's RowSource property to =PrinterList()

Usage:

  1. Save the current setting of the Windows Default Printer to a string.
  2. Set it to the printer selected by the user.
  3. Print the Report, using either OpenReport or PrintOut command.
  4. Return the Default Printer to the saved string.

The SetDevice procedure takes care of items 1, 2 and 4 as in the example below

SetDevice "The selected printer name" 'This saves the current Printer setting
DoCmd.Printout ...
SetDevice ""  'This sets the Default Printer to it's previous setting
Home Contents