Results 1 to 4 of 4

Thread: [RESOLVED] Printers.Count Error

  1. #1

    Thread Starter
    Lively Member jkmcgrath's Avatar
    Join Date
    Dec 2004
    Posts
    79

    Resolved [RESOLVED] Printers.Count Error

    Hi,

    still having printer woes lol. This code gives me an "Data member or method not found" error in one project but not the other. If I use the Printers.Form1.Count then it works. I cant understand why it does in one but not the other. And ideas?

    VB Code:
    1. 'Load up the Printers installed
    2.     Dim i As Integer ' For printer collection
    3.     For i = 0 To Printers.Count - 1 'Gets the printers installed on the sytem
    4.         cboPrinters.AddItem Replace(Printers(i).DeviceName & "[" & Printers(i).DriverName & "]", "[winspool]", "")
    5.     Next
    6.     cboPrinters.Text = Printer.DeviceName
    7.      'MsgBox Printers.Form1.Count
    Thanks
    John
    Just an infant in VB years

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printers.Count Error

    Try using VB.Printers as opposed to just Printers
    VB Code:
    1. Private MyPrinters As Printer
    2.  
    3. Private Sub Form_Load()
    4. Dim MyPrinters As Printer
    5. 'add all installed printers to combo box (if any)
    6. If VB.Printers.Count <= 0 Then
    7.    cboPrinters.AddItem "No Printer(s) Installed"
    8. Else
    9.     For Each MyPrinters In Printers
    10.         cboPrinters.AddItem MyPrinters.DeviceName
    11.     Next
    12. End If
    13.     cboPrinters.ListIndex = 0
    14. End Sub

  3. #3

    Thread Starter
    Lively Member jkmcgrath's Avatar
    Join Date
    Dec 2004
    Posts
    79

    Re: Printers.Count Error

    Hack, Thanks.

    When I first tried your example it errored also. So I rebooted and tried my original again in a new project and it worked as well as did yours.

    So I went back to the one that would error and it still will error.

    The only difference this time to last was placing Option Explicit from the very start of the project and not after it had failed.

    Not sure what is up with that.
    Just an infant in VB years

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printers.Count Error

    Quote Originally Posted by jkmcgrath
    The only difference this time to last was placing Option Explicit from the very start of the project and not after it had failed.

    Not sure what is up with that.
    Hmmmm...all Option Explicit does (which you should have turned on by default) is require that you declare variables before using them. Without it your program shouldn't misbehave. It sounds like a coincidence.

Posting Permissions

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



Click Here to Expand Forum to Full Width