Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2002
    Posts
    10

    Question Unanswered: Printer Control in Access

    Hi,

    Does anyone know how to use printer control in Access? In VBA there is something call Printer and Printers object; however, these two seems not available in Access.

    What I try to do is to choose a PDFWriter dynamically, set a directory for it to save file(s) to, and assign filenames for those generated reports.

    Thanks.


    AL

  2. #2
    Join Date
    Apr 2002
    Posts
    139

    Re: Printer Control in Access

    Have not used them yet, but believe from Access XP on you can find the Printers and Printer available in Access-VBA.

    In Access 97 these are not available, I'm not sure about A2000.

    Of course in all versions you can always set a specific (pdf-)printer in the report's print layout tab sheet.

    hth

  3. #3
    Join Date
    Nov 2002
    Location
    San Francisco
    Posts
    251
    microsoft improved printing feature in AccessXP.

    in previous versions you cannot easily use Access Object Model:
    you cannot choose printer and it's properties
    and you cannot change report's page size without switching to design mode

    changing report's page size is OK, you just have to switch to design mode and back.... silly but it works... i used it a lot for printing to envelopes feeder on differnet printers....


    for setting printer, you can use scripting....

    Sub SetDefaultPrinter(InputPrinter As String)
    Dim WSHNetwork As Object
    Set WSHNetwork = CreateObject("WScript.Network")
    WSHNetwork.SetDefaultPrinter InputPrinter
    Set WSHNetwork = Nothing
    End Sub

    Sub ListAllPrinterinNetwork()
    Dim WSHNetwork As Object
    Dim oPrinters As Object
    Dim i As Byte

    Set WSHNetwork = CreateObject("WScript.Network")
    Set oPrinters = WSHNetwork.EnumPrinterConnections
    For i = 0 To oPrinters.Count - 1
    Debug.Print oPrinters.Item(i)
    Next
    End Sub



    i didn't play with PDF and autoprint to specific file, try to play with registry

    HKEY_LOCAL_MACHINE/System/CurrentControlSet/Control/Print/Printers



    jiri
    Last edited by playernovis; 01-04-03 at 18:57.

  4. #4
    Join Date
    Dec 2002
    Posts
    10

    Unhappy

    Thank you, Playernovis and Marion.

    Playernovis, with your code, I can set the default printer; however, what code to GET the default printer? What it means is that after I switch to another printer, do something, then I have to switch back.
    I try WSHNetwork.Printer, WSHNetwork.DefaultPrinter, WSHNetwork.SetDefaultPrinter. None of these line works.

    AL


    Originally posted by playernovis
    microsoft improved printing feature in AccessXP.

    in previous versions you cannot easily use Access Object Model:
    you cannot choose printer and it's properties
    and you cannot change report's page size without switching to design mode

    changing report's page size is OK, you just have to switch to design mode and back.... silly but it works... i used it a lot for printing to envelopes feeder on differnet printers....


    for setting printer, you can use scripting....

    Sub SetDefaultPrinter(InputPrinter As String)
    Dim WSHNetwork As Object
    Set WSHNetwork = CreateObject("WScript.Network")
    WSHNetwork.SetDefaultPrinter InputPrinter
    Set WSHNetwork = Nothing
    End Sub

    Sub ListAllPrinterinNetwork()
    Dim WSHNetwork As Object
    Dim oPrinters As Object
    Dim i As Byte

    Set WSHNetwork = CreateObject("WScript.Network")
    Set oPrinters = WSHNetwork.EnumPrinterConnections
    For i = 0 To oPrinters.Count - 1
    Debug.Print oPrinters.Item(i)
    Next
    End Sub



    i didn't play with PDF and autoprint to specific file, try to play with registry

    HKEY_LOCAL_MACHINE/System/CurrentControlSet/Control/Print/Printers



    jiri

  5. #5
    Join Date
    Nov 2002
    Location
    San Francisco
    Posts
    251
    i didn't find such command in WSH :-(

    i always went to registry.....

    WinNT 4 & Win2k
    HKEY_CURRENT_USER\Software\microsoft\windows nt\currentversion\windows\ key 'DEVICE'

    I took everything until word winspool ....


    Public Function GetDefaultPrinterName() As String
    Dim WshShell As Object
    Set WshShell = CreateObject("WScript.Shell")
    GetDefaultPrinterName = WshShell.RegRead("HKEY_CURRENT_USER\Software\micro soft\windows nt\currentversion\windows\device")
    GetDefaultPrinterName = Left(GetDefaultPrinterName, InStr(1, GetDefaultPrinterName, ",winspool") - 1)
    Set WshShell = Nothing
    End Function




    It looks strange, but it worked just fine.....


    jiri
    Last edited by playernovis; 01-07-03 at 01:09.

Posting Permissions

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