+ Reply to Thread
Results 1 to 6 of 6

Printing Problems

  1. #1
    Registered User
    Join Date
    06-29-2006
    Posts
    28

    Printing Problems

    Hello,

    I have a combo box which automatically fills up with the printers that are added to the computer's system. And then when the user presses the print button, I have the following code:

    Please Login or Register  to view this content.
    Where printer.Value is the value of the combo box which has a list of printers.

    But I get the

    Run-Time error '1004'
    Method 'ActivePrinter' of object '_Application' failed
    What is the problem here?

  2. #2
    NickHK
    Guest

    Re: Printing Problems

    I'm not sure if "Printer" is a reserved word, but it's probably best
    avoided.
    Sound like the .Text is not a valid setting.
    Is it something like "\\MyNetwork\Copier on Ne04:"

    NickHK

    "FCC" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hello,
    >
    > I have a combo box which automatically fills up with the printers that
    > are added to the computer's system. And then when the user presses the
    > print button, I have the following code:
    >
    >
    > Code:
    > --------------------
    >
    > Application.ActivePrinter = printer.Text
    >
    > --------------------
    >
    >
    > Where printer.Value is the value of the combo box which has a list of
    > printers.
    >
    > But I get the
    >
    > >
    > > Run-Time error '1004'
    > > Method 'ActivePrinter' of object '_Application' failed
    > >

    >
    > What is the problem here?
    >
    >
    > --
    > FCC
    > ------------------------------------------------------------------------
    > FCC's Profile:

    http://www.excelforum.com/member.php...o&userid=35888
    > View this thread: http://www.excelforum.com/showthread...hreadid=558282
    >




  3. #3
    Registered User
    Join Date
    06-29-2006
    Posts
    28
    I got rid of the .text but I still got the error:

    I made a msg box to see what the printer variable would say and I got a printer name of:

    "EPSON Stylus Photo 915"

    Which is a printer on setup on my computer, and the one that I selected from the combo box.

    What is causing this problem!!!

  4. #4
    NickHK
    Guest

    Re: Printing Problems

    How are you generating your list of printers in VBA ?

    NickHK

    "FCC" <[email protected]> wrote in message
    news:[email protected]...
    >
    > I got rid of the .text but I still got the error:
    >
    > I made a msg box to see what the printer variable would say and I got a
    > printer name of:
    >
    > "EPSON Stylus Photo 915"
    >
    > Which is a printer on setup on my computer, and the one that I selected
    > from the combo box.
    >
    > What is causing this problem!!!
    >
    >
    > --
    > FCC
    > ------------------------------------------------------------------------
    > FCC's Profile:

    http://www.excelforum.com/member.php...o&userid=35888
    > View this thread: http://www.excelforum.com/showthread...hreadid=558282
    >




  5. #5
    Registered User
    Join Date
    06-29-2006
    Posts
    28
    I am using this code that I found on the web:

    Please Login or Register  to view this content.
    And this is the code I am using to populate the combo box
    Please Login or Register  to view this content.

  6. #6
    NickHK
    Guest

    Re: Printing Problems

    Yes, the strings from this function do not match the strings returned from
    ?Application.ActivePrinter
    You will see the port info is missing.
    It's easier to use
    Application.Dialogs(xlDialogPrinterSetup).Show
    or
    Application.Dialogs(xlDialogPrint).Show

    NickHK

    "FCC" <[email protected]> wrote in message
    news:[email protected]...
    >
    > I am using this code that I found on the web:
    >
    >
    > Code:
    > --------------------
    >
    > Const PRINTER_ENUM_CONNECTIONS = &H4
    > Const PRINTER_ENUM_LOCAL = &H2
    >
    > Private Declare Function EnumPrinters Lib "winspool.drv" Alias

    "EnumPrintersA" _
    > (ByVal flags As Long, ByVal name As String, ByVal Level As Long, _
    > pPrinterEnum As Long, ByVal cdBuf As Long, pcbNeeded As Long, _
    > pcReturned As Long) As Long
    >
    > Private Declare Function PtrToStr Lib "kernel32" Alias "lstrcpyA" _
    > (ByVal RetVal As String, ByVal Ptr As Long) As Long
    >
    > Private Declare Function StrLen Lib "kernel32" Alias "lstrlenA" _
    > (ByVal Ptr As Long) As Long
    >
    > -----------------
    > Public Function ListPrinters() As Variant
    >
    > Dim bSuccess As Boolean
    > Dim iBufferRequired As Long
    > Dim iBufferSize As Long
    > Dim iBuffer() As Long
    > Dim iEntries As Long
    > Dim iIndex As Long
    > Dim strPrinterName As String
    > Dim iDummy As Long
    > Dim iDriverBuffer() As Long
    > Dim StrPrinters() As String
    >
    > iBufferSize = 3072
    >
    > ReDim iBuffer((iBufferSize \ 4) - 1) As Long
    >
    > 'EnumPrinters will return a value False if the buffer is not big enough
    > bSuccess = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or _
    > PRINTER_ENUM_LOCAL, vbNullString, _
    > 1, iBuffer(0), iBufferSize, iBufferRequired, iEntries)
    >
    > If Not bSuccess Then
    > If iBufferRequired > iBufferSize Then
    > iBufferSize = iBufferRequired
    > Debug.Print "iBuffer too small. Trying again with "; _
    > iBufferSize & " bytes."
    > ReDim iBuffer(iBufferSize \ 4) As Long
    > End If
    > 'Try again with new buffer
    > bSuccess = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or _
    > PRINTER_ENUM_LOCAL, vbNullString, _
    > 1, iBuffer(0), iBufferSize, iBufferRequired, iEntries)
    > End If
    >
    > If Not bSuccess Then
    > 'Enumprinters returned False
    > MsgBox "Error enumerating printers."
    > Exit Function
    > Else
    > 'Enumprinters returned True, use found printers to fill the array
    > ReDim StrPrinters(iEntries - 1)
    > For iIndex = 0 To iEntries - 1
    > 'Get the printername
    > strPrinterName = Space$(StrLen(iBuffer(iIndex * 4 + 2)))
    > iDummy = PtrToStr(strPrinterName, iBuffer(iIndex * 4 + 2))
    > StrPrinters(iIndex) = strPrinterName
    > Next iIndex
    > End If
    >
    > ListPrinters = StrPrinters
    >
    > End Function
    >
    > ----------------
    > Public Function IsBounded(vArray As Variant) As Boolean
    >
    > 'If the variant passed to this function is an array, the function will

    return True;
    > 'otherwise it will return False
    > On Error Resume Next
    > IsBounded = IsNumeric(UBound(vArray))
    >
    > End Function
    >
    > ----------
    >
    > --------------------
    >
    >
    > And this is the code I am using to populate the combo box
    >
    > Code:
    > --------------------
    >
    > Private Sub userForm_Initialize()
    >
    > Dim StrPrinters As Variant, x As Long
    >
    > StrPrinters = ListPrinters
    >
    > 'Fist check whether the array is filled with anything, by calling

    another function, IsBounded.
    > If IsBounded(StrPrinters) Then
    > For x = LBound(StrPrinters) To UBound(StrPrinters)
    > printer.AddItem StrPrinters(x)
    > Next x
    > printer.Value = StrPrinters(1)
    > Else
    > Debug.Print "No printers found"
    > End If
    >
    > End Sub
    >
    > --------------------
    >
    >
    > --
    > FCC
    > ------------------------------------------------------------------------
    > FCC's Profile:

    http://www.excelforum.com/member.php...o&userid=35888
    > View this thread: http://www.excelforum.com/showthread...hreadid=558282
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1