How to use multiple printers in MSACCESS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wassimdaccache
    New Member
    • Apr 2007
    • 222

    How to use multiple printers in MSACCESS

    Hello everybody


    I do have a form called invoices I'm using a this code to print a report called invoices

    Code:
       DoCmd.OpenReport "Invoices", acViewPreview, "", "[Forms]![Invoices]![InvoiceID]=[InvoiceID]", acHidden
    I do have 2 printers installed in my computer "HP" and "Epson "
    How can I ask user before he prints the invoices report to chose which printer want to use ...???
    is there any method that can find all printers installed on the computer and let user choose the one that he needs to use ????
    I'm using windows xp SP2 and Microsoft access 2003


    thank you to all
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by wassimdaccache
    Hello everybody


    I do have a form called invoices I'm using a this code to print a report called invoices

    Code:
       DoCmd.OpenReport "Invoices", acViewPreview, "", "[Forms]![Invoices]![InvoiceID]=[InvoiceID]", acHidden
    I do have 2 printers installed in my computer "HP" and "Epson "
    How can I ask user before he prints the invoices report to chose which printer want to use ...???
    is there any method that can find all printers installed on the computer and let user choose the one that he needs to use ????
    I'm using windows xp SP2 and Microsoft access 2003


    thank you to all
    1. Populate a Combo List with a List of available Printers for the User to select from.
      [CODE=vb]
      Dim prn As Printer

      Me![cboInstalledPri nters].RowSourceType = "Value List"

      For Each prn In Application.Pri nters
      'Populate a Combo Box with a list of Installed Printers
      Me![cboInstalledPri nters].AddItem prn.DeviceName
      Next
      [/CODE]
    2. Assign the specifically chosen Printer to the Report.
      [CODE=vb]
      If Not IsNull(Me![cboInstalledPri nters]) Then
      'Open Hidden so you can assign a specific Printer to the Report
      DoCmd.OpenRepor t "rptShipper s", acViewPreview, , , acHidden
      'assign selected Printer
      Set Reports!rptShip pers.Printer = Application.Pri nters(Me![cboInstalledPri nters].ListIndex)
      'Print the Report
      DoCmd.OpenRepor t "rptShipper s", acViewNormal, , , acWindowNormal
      End If
      [/CODE]

    Comment

    • bany
      New Member
      • Jan 2008
      • 4

      #3
      Hi!
      First of all create a module Name: PrintersList and place this code incide:
      =============== =============== =============== =========
      Option Compare Database
      Option Explicit
      Private Declare Function GetProfileSecti on _
      Lib "kernel32" Alias "GetProfileSect ionA" _
      (ByVal lpAppName As String, ByVal lpReturnedStrin g As String, _
      ByVal lngSize As Long) As Long

      Private Const adhcMaxSection = 10000
      Function PrinterChooser( ) As String

      Dim strMatchstr As String
      Dim strItems() As String
      Dim strPrinters() As String
      Dim strDetails() As String
      Dim NoPrinter(20) As String
      Dim AutoPrinter(20) As String
      Dim PrinterPort(20) As String
      Dim list As String
      Dim strBuffer As String
      Dim intCount As Integer
      Dim i As Integer

      On Error GoTo HandleErrors
      strBuffer = Space(adhcMaxSe ction)
      intCount = GetProfileSecti on("Devices", strBuffer, adhcMaxSection - 1)
      strMatchstr = Left$(strBuffer , intCount)
      If Len(strMatchstr ) = 0 Then
      intCount = 0
      Else
      strPrinters = Split(strMatchs tr, vbNullChar)
      ReDim aDevList(LBound (strPrinters) To UBound(strPrint ers))
      For i = LBound(strPrint ers) To UBound(strPrint ers)
      If Len(strPrinters (i)) > 0 Then
      strItems = Split(strPrinte rs(i), "=")
      NoPrinter(i) = strItems(0)
      strDetails = Split(strItems( 1), ",")
      AutoPrinter(i) = strDetails(0)
      PrinterPort(i) = strDetails(1)
      list = list & NoPrinter(i) & ";" _
      & AutoPrinter(i) & ";" & PrinterPort(i) & ";"

      End If
      Next i
      End If

      ExitHere:
      PrinterChooser = list
      Exit Function

      HandleErrors:
      Select Case Err.Number
      Case Else
      Err.Raise Err.Number, Err.Source, Err.Description
      End Select
      End Function

      Function DefaultPrinter( ) As String

      Dim strMatchstr As String
      Dim NoPrinter As String
      Dim strBuffer As String
      Dim intCount As Integer
      Dim i As Integer
      Dim PosDeb As Integer
      Dim PosFin As Integer
      Dim Longueur As Integer
      On Error GoTo HandleErrors
      DefaultPrinter = ""
      strBuffer = Space(adhcMaxSe ction)
      intCount = GetProfileSecti on("Windows", strBuffer, adhcMaxSection - 1)
      strMatchstr = Left$(strBuffer , intCount)

      If Len(strMatchstr ) = 0 Then
      intCount = 0
      Else
      PosDeb = InStr(1, strMatchstr, "Device=", vbTextCompare) + 7
      PosFin = InStr(PosDeb, strMatchstr, ",", vbTextCompare)
      Longueur = PosFin - PosDeb
      DefaultPrinter = Mid(strMatchstr , PosDeb, Longueur)
      End If

      ExitHere:
      Exit Function

      HandleErrors:
      Select Case Err.Number
      Case Else
      Err.Raise Err.Number, Err.Source, Err.Description
      End Select
      End Function

      =============== =============== =============== ========
      1-After this module create a form Name: PrinterChooser
      And then incide the form create 1 text box name it:DefaultPrint er
      go to data...control source and put this : =DefaultPrinter ()
      =============== =============== =============== ========
      2-And then create a conboBox Name it:PrinterList
      go to format.....Colu mn count=3 and then to .......Column Width=1.575";0. 7875";0.7875"
      =============== =============== =============== ========
      3-go to event of the combo box OnClick put this:
      =============== =============== =============== ========
      Option Compare Database
      Private Declare Function WriteProfileStr ing _
      Lib "kernel32" Alias "WriteProfileSt ringA" _
      (ByVal lpszSection As String, ByVal lpszKeyName As String, _
      ByVal lpszString As String) As Long

      Private Declare Function SendMessageTime outStr _
      Lib "user32" Alias "SendMessageTim eoutA" _
      (ByVal hwnd As Long, ByVal msg As Long, _
      ByVal wParam As Long, ByVal lParam As String, _
      ByVal fuFlags As Long, ByVal uTimeout As Long, _
      lpdwResult As Long) As Long


      Private Const WM_WININICHANGE = &H1A
      Private Const SMTO_NORMAL = &H0
      Private Const HWND_BROADCAST = &HFFFF&

      Private Sub Form_Load()
      Me.PrinterList. RowSource = PrinterChooser( )
      End Sub

      Private Sub PrinterList_Cli ck()
      Dim strBuffer As String

      strBuffer = Me.PrinterList. Column(0) & "," & _
      Me.PrinterList. Column(1) & "," & Me.PrinterList. Column(2)

      Call WriteProfileStr ing("Windows", _
      "Device", strBuffer)
      Call SendMessageTime outStr(HWND_BRO ADCAST, WM_WININICHANGE , _
      0, "Windows", SMTO_NORMAL, 1000, 0)
      Me.DefaultPrint er.Requery
      End Sub

      =============== =============== =============== ===========

      Comment

      Working...