Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2003
    Posts
    3

    Unanswered: Changing printer settings

    Hi,

    I have an application with a report that must use the A4 paper size (which is bigger than the standard and normally default Letter size).

    To initialize the printer I run the following code before opening the report, but for some reason the changes are not saved in the printer settings and the report opens Letter size.

    Suggestions anybody?


    Public Function SetPrinterProperties(pDeviceName As String, hWnd As Long) As Boolean
    On Error GoTo ErrorHandler
    Dim lRet As Long
    Dim hPrinter As Long
    Dim typPD As PRINTER_DEFAULTS
    Dim pDevMode As type_DEVMODE
    Dim aDevMode() As Byte
    Dim hPrtDC As Long

    Const DM_PAPERSIZE = &H2&
    Const DM_PAPERLENGTH = &H4&
    Const DM_PAPERWIDTH = &H8&
    Const DM_OUT_BUFFER = 2
    Const DM_IN_PROMPT = 4
    Const DM_IN_BUFFER = 8

    'Open printer and get Handle
    typPD.pDatatype = 0
    typPD.pDevMode = 0
    typPD.pDesiredAccess = PRINTER_ALL_ACCESS
    lRet = OpenPrinter(pDeviceName, hPrinter, typPD)

    'Get size of DevMode (including private printer specific extra's)
    lRet = DocumentProperties(hWnd, hPrinter, pDeviceName, Null, Null, 0)
    ReDim aDevMode(1 To lRet)

    'Get default properties
    lRet = DocumentProperties(hWnd, hPrinter, pDeviceName, aDevMode(1), Null, DM_OUT_BUFFER)

    'Copy buffer to structure
    Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode))

    'Make changes to properties
    pDevMode.intPaperSize = 9
    pDevMode.intPaperLength = 2969
    pDevMode.intPaperWidth = 2099

    'Copy your changes back to buffer
    Call CopyMemory(aDevMode(1), pDevMode, Len(pDevMode))

    'Save changes
    lRet = DocumentProperties(hWnd, hPrinter, pDeviceName, aDevMode(1), aDevMode(1), DM_IN_BUFFER Or DM_OUT_BUFFER)

    ErrorHandler:

    'Close printer
    If hPrinter <> 0 Then
    lRet = ClosePrinter(hPrinter)
    End If

    End Function

  2. #2
    Join Date
    Oct 2003
    Location
    New York
    Posts
    23
    Have you tried setting the properties (Page Setup) within the actual report?

  3. #3
    Join Date
    Jun 2003
    Location
    UK
    Posts
    68
    Not sure if this will help as it only sets the printer for individul reports but it does allow you to specify papersize;

    Private Sub cmdPreview_Click()
    Dim stDocName As String
    Dim prtDefault As Printer

    'Set the printer default Users Printer
    Set Application.Printer = Application.Printers("\\Dept1\Label_Printer")
    Set prtDefault = Application.Printer

    'Opens named report in preview mode and hides the current form and then sets the reports printer to above printer
    stDocName = "rptLabelA"
    DoCmd.OpenReport stDocName, acPreview, , , acWindowNormal
    Me.Visible = False
    Reports(stDocName).Printer = prtDefault

    'Set the printer tray for Dept 1 Printer
    prtDefault.Duplex = acPRDPSimplex 'single sided print
    prtDefault.PaperSize = 130 'papersize 130 is a custom size

    End Sub

    I use a custom size paper but you can specify A4.

    Regards

    Paul

  4. #4
    Join Date
    Apr 2003
    Posts
    3
    Paul,

    I'm sorry. I should have been more clear.
    I use Access 2000 and there is no Application.Printers to make life easy in access 2000.

    Roeland.

  5. #5
    Join Date
    Jun 2003
    Location
    UK
    Posts
    68
    Sorry its taken me so long to get back. You'll need to refence the Office and word librarys. In the code environment select Tools > References and then scroll down to select : Microsoft Office 9.0 Object Library and
    Microsoft Word 9.0 Object Library. The functionality is in one of these.

    Hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •