[Access] How to specify printer for PrintOut method?-VBForums
Results 1 to 10 of 10

Thread: [Access] How to specify printer for PrintOut method?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2008
    Posts
    29

    [Access] How to specify printer for PrintOut method?

    I am using Access 97 to print out the form.
    I would like to have one command button whereby it can specify a canon printer to print the form and another command to use Microsoft office document image writer to save the same form as an image.

    Code:
    Private Sub Print_Click()
    ‘using canon printer to print the form
    Docmd.PrintOut
    
    End Sub
    
    Private Sub Save_Click()
    ‘using Microsoft office document image writer to save the form as a .mdi file
    Docmd.PrintOut’
    
    End Sub
    Is there a way to specify which printer to print the form?

    Thanks

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,531

    Re: [Access] How to specify printer for PrintOut method?

    Set your printer before PrintOut command:
    Code:
    ActivePrinter = "Generic / Text Only"   '<-- Replace with your printer name
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog • 101 LINQ Samples • JSON Validator • XML Schema Validator • "How Do I" videos on MSDN • VB.NET and C# Comparison • Good Coding Practices • VBForums Reputation Saver • String Enum • Super Simple Tetris Game


    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,809

    Re: [Access] How to specify printer for PrintOut method?

    dunno with access, but with excel you have to specify the port as well as the printer name
    activeprinter = "someprinter on someport"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: [Access] How to specify printer for PrintOut method?

    Try this:
    Code:
    Private Sub Print_Click()
       PrintTo "Adobe PDF" '-- replace with your Cannon printer DeviceName
    End Sub
    
    Private Sub Save_Click()
       PrintTo "Microsoft Office Document Image Writer"
    End Sub
    
    Private Sub PrintTo(PrinterDeviceName As String)
       Dim myCurPrinter As Printer
       
       Set myCurPrinter = Me.Printer
       Me.Printer = Application.Printers(PrinterDeviceName)
       DoCmd.PrintOut
       Set Me.Printer = myCurPrinter
    End Sub
    To get a list of all your printer DeviceNames, use this:
    Code:
    Sub AllMyPrinterDeviceNames()
       Dim aPrinter As Printer
       
       For Each aPrinter In Application.Printers
          Debug.Print aPrinter.DeviceName
       Next
    End Sub
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2008
    Posts
    29

    Re: [Access] How to specify printer for PrintOut method?

    anhn,

    a) PrintTo "Adobe PDF" '-- replace with your Cannon printer DeviceName

    this cannot work as PrintTo need to be defined as a variable.
    what should PrintTo dim as ?

    b) Dim myCurPrinter As Printer

    this also cannot work for A97 as there is an error (user-defined type not defined). A97 cannot dim variable as Printer

    Pradeep1210,

    c) ActivePrinter = "Generic / Text Only" '<-- Replace with your printer name

    this also cannot work as what should ActivePrinter be dim as ?

    thanks.

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,531

    Re: [Access] How to specify printer for PrintOut method?

    Application.ActivePrinter = "Generic / Text Only"
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog • 101 LINQ Samples • JSON Validator • XML Schema Validator • "How Do I" videos on MSDN • VB.NET and C# Comparison • Good Coding Practices • VBForums Reputation Saver • String Enum • Super Simple Tetris Game


    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,531

    Re: [Access] How to specify printer for PrintOut method?

    Sorry.. For access, it is Printer, not ActivePrinter

    This is from Access help files.

    This is how you set the active printer:
    Code:
    Dim prtDefault As Printer
    
    Set Application.Printer = Application.Printers(0)
    Set prtDefault = Application.Printer
    With prtDefault
        MsgBox "Device name: " & .DeviceName & vbCr _
            & "Driver name: " & .DriverName & vbCr _
            & "Port: " & .Port
    End With
    And this is how you can search for a specific printer:
    Code:
    Dim prtLoop As Printer
    
    For Each prtLoop In Application.Printers
        With prtLoop
            MsgBox "Device name: " & .DeviceName & vbCr _
                & "Driver name: " & .DriverName & vbCr _
                & "Port: " & .Port
        End With
    Next prtLoop
    Pradeep
    Last edited by Pradeep1210; Dec 3rd, 2008 at 12:59 AM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog • 101 LINQ Samples • JSON Validator • XML Schema Validator • "How Do I" videos on MSDN • VB.NET and C# Comparison • Good Coding Practices • VBForums Reputation Saver • String Enum • Super Simple Tetris Game


    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,809

    Re: [Access] How to specify printer for PrintOut method?

    this cannot work as PrintTo need to be defined as a variable.
    what should PrintTo dim as ?
    the printer name should be a string, you would need to save the devicename
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: [Access] How to specify printer for PrintOut method?

    The code in post#4 does not work for Access-97.

    With Access-97, it is much harder and perhaps there is only one way the code has to do is:
    1. Save the system default printer name.
    2. Change the system default printer to the printer you want to print to.
    3. Print the form/report.
    4. Reset the system default printer.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2008
    Posts
    29

    Re: [Access] How to specify printer for PrintOut method?

    thanks all for your help

    i think A97 will be harder to resolve while newer versions of access will be easier.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.