Results 1 to 9 of 9

Thread: Printer Object

  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Printer Object

    This was a simple request.....
    I have been asked to ensure that a printer (by default) only prints one copy of any document.
    My code:
    Dim objDefPrntr As Printer

    Set objDefPrntr = Printers(0)

    objDefPrntr.Copies = 1
    returns an error that 'Copies' is read only. error 383

    can anyone explain to me why this is read only at runtime please and also give me a clue as to how I can enforce the requirement?

    The need stems from a rogue application in use that leaves the Copies default to whatever the last setting was and so causes a lot of paper waste as people forget to reset the value before printing form other apps.

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printer Object

    If you use the PrintOut method, you can set the number of copies:

    Application.PrintOut FileName:="", range:=wdPrintAllDocument, _
    Item:= wdPrintDocumentContent, Copies:=3, Pages:=""

    I take it that the property of the object is read/only until you actually use the method on the object to print something.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printer Object

    I think this may be Word ?
    how does this translate into VB6 ?

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printer Object

    According to the VB6 help the printer.copies property is read/write. I've tested it in IDE and run the code and it appear to work. I haven't tried printing, but it does not give me a read only message. Maybe runtime is different.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Printer Object

    I tried this in VB6 and it worked just fine, no matter what number I set for the copies.

    <pre>Private Sub mnuPrint_Click()
    Dim strMsg As String
    Dim objPrn As Object

    Set objPrn = Printer
    With objPrn
    .Copies = 1
    End With

    strMsg = "This tests the copies property of Printer." & vbCrLf _
    & "I am printing " & objPrn.Copies & " of this message."

    Printer.Print strMsg
    Printer.EndDoc
    Set objPrn = Nothing
    End Sub 'mnuPrint_Click()</pre>

    Charlotte

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printer Object

    Charlotte,
    This is running without the error - many thanks.
    What was wrong with my code ? Why does
    Dim objPrn as object
    set objPrn = printer
    work better than
    dim objPrn as printer
    set objprn = printer(0)?
    is my version incorrect (other than it doesnt work) in its structure ?

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Printer Object

    The difference is that in the late binding I used, Printer is the current printer, while you're trying to specify a printer. On-line help says this:
    <hr>If you use the Printers collection to specify a particular printer, as in Printers(3), you can only access properties on a read-only basis. To both read and write the properties of an individual printer, you must first make that printer the default printer for the application.<hr>
    Charlotte

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printer Object

    Thanks, a demonstration of late versus early binding that makes sense to me [img]/forums/images/smilies/smile.gif[/img]

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Printer Object

    The only reason I used late binding was because I was setting the object variable to the default printer, so I didn't really need to dim the object as a printer and then specify which printer. If I were, I'd probably use early binding so intellisense would kick in.
    Charlotte

Posting Permissions

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