Results 1 to 4 of 4
  1. #1
    TedT is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    10

    Assigning printers to a document type for automated printing


    Hi,

    I am writing an app for printing labels and documents on a production line. So for every "product" built, their will be a number of labels, manuals etc that will be printed on demand. I will want to be able to assign the correct printer/tray/paper to each document type so that when the line worker selects a product and selects print - all the correct documents will come out of the correct printer. So I guess I need to figure out how to use the printer dialog to select a printer and assign it to a document type and save this tot he database, but also to set the printer settings for each printer.

    For example, product model XYZ will need a 1"x2" product label, a 2"x4" carton label and a 8.5"x11" duplex manual. So in the admin dialog, the admin will assign these three "items" to the product. But each item should have a printer with settings assigned to it so all three items print, and settings like duplex will need to be saved for this document printer. Once done, the line user will just select the product and select print and all three documents will print.

    So a summary of questions:
    1) Code to open printer dialog and get the printer and maybe the settings
    2) Code to take that info and store it to the database

    Any ideas on how to do this and any comments would be great.

    TedT

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The capabilities of the printer via its drivers will determine the capabilities of the Printer object in VBA.

    I prefer to use VBA and go after a printer name vs. port name. If you have tight enough control on printer names during the installation of hardware you can hard code your VBA using the printer name. Use error trapping that allows the user to select an available printer in case the hard coded printer is offline.

    It has been a while and I would have to look for examples of working code to interact with reports and adjust printer properties.

    To get you started, here is some code to enumerate available printers. You can instantaite a printer object and adjust its behavior through its proerties. Set the report's printer to = the instantiated object and then print the report.

    Code:
    Dim prtMyPrinter As Printer
    Dim prtName As Printer
    Dim intIndex As Integer
    intIndex = 0
    For Each prtName In Application.Printers
    With prtName
     Debug.Print "Index: " & intIndex & vbCr _
     & "Device name: " & .DeviceName & vbCr _
     & "Driver name: " & .DriverName & vbCr _
     & "Port: " & .Port & vbCr _
     & "*****************************************************************"
    End With
     intIndex = intIndex + 1
    Next
     
    Set prtMyPrinter = Application.Printers.Item(0)
    Debug.Print "The first printer in the list with index zero is named" & vbCr _
    & prtMyPrinter.DeviceName & vbCr _
    & "*****************************************************************"
    Set prtMyPrinter = Nothing
    Set prtMyPrinter = Application.Printers.Item(1)
    Debug.Print "The second printer in the list with index one is named" & vbCr _
    & prtMyPrinter.DeviceName & vbCr _
    & "*****************************************************************"
    Set prtMyPrinter = Nothing
    Another approach is to make a separate report for each printer and set of business rules. Each report object would have the printer properties set in stone.

  3. #3
    TedT is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    10
    I was hoping to avoid any hand coding once the app was done. A production supervisor would go to the admin side of the app to select labels or documents and I wanted them to be able to open the printer dialog and select a printer to tie it to the item. I was hoping no outside coding would be necessary, maybe I am too optimistic. I thought you can get printer info passed from a printer dialog the way I do with the file dialog on files I want to load, save or save the path to.
    But thanks for the quick reply!
    Ted

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe using API's to the OS. Here is an example using Visual Basic and the winspool.drv.
    http://support.microsoft.com/kb/198860

    So the above link will work if that is the driver associated with the printer. You would still need to enumerate your active printers and see what driver for what API.

    Not sure why you would take that approach when the Printer object in VBA has properties you can adjust.
    http://msdn.microsoft.com/en-us/libr...ffice.15).aspx

    If you do not want to use VBA, set the properties for the printer in the report. If you want your app to be dynamic during RunTime, use VBA

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 01-23-2014, 09:36 AM
  2. Printing report on different printers
    By mujaqo in forum Reports
    Replies: 3
    Last Post: 01-09-2014, 06:57 AM
  3. Replies: 4
    Last Post: 06-20-2013, 12:19 PM
  4. Changing Printers Code produces an error
    By Perceptus in forum Programming
    Replies: 4
    Last Post: 01-15-2013, 08:33 PM
  5. Replies: 1
    Last Post: 10-18-2011, 07:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums