CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Printer Issue

  1. #1
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Question Printer Issue

    Can anyone tell me ??? . Why the Following Error is Not Coming in Message Box ???.here are the following Code What I have writtem .the error message needs to be come in MessageBox on Runtime !!!.
    Code:
    Public Sub btprint_Click()
    On Error GoTo errhnd
    Me.PrintForm
    errhnd:
    MsgBox Err.Description
    End Sub
    Attached Images Attached Images  
    Last edited by firoz.raj; December 26th, 2010 at 03:09 AM.

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,345

    Re: Printer Issue

    You have to place an Exit Sub above the Label for the Error Handler otherwise it will always display the message error or not.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Question Re: Printer Issue

    You have to place an Exit Sub above the Label for the Error Handler otherwise it will always display the message error or not
    I have tried Exit Sub after printing the specific form .But still the same !!!
    Code:
    Public Sub Btprint_Click()
    On Error GoTo errHnd
    Me.PrintForm
    Exit Sub
    errHnd:
    MsgBox Err.Description
    End Sub

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Printer Issue

    Try to send ONE CHARACTER to the printer, to see if it is alive. I usually do that when the program starts. It reads the config file to see what printers were connected last time, and connects them again.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,345

    Re: Printer Issue

    Printer error means that there is an error with your default printer.
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Question Re: Printer Issue

    Try to send ONE CHARACTER to the printer, to see if it is alive. I usually do that when the program starts. It reads the config file to see what printers were connected last time, and connects them again.
    Yes Printer is Not alive other than administrator account . i did not get any error in the administrator Acccount .i simple want if Printer is Not Alive in other A/C.it needs to give Error Message In MessageBox .so let me know please !!!.

  7. #7
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,345

    Re: Printer Issue

    It is giving you an error message. If you want it to display a different message then trap the error code and display the message of your choice.
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Question Re: Printer Issue

    It is giving you an error message. If you want it to display a different message then trap the error code and display the message of your choice.
    When I Use Step in at Runtime .When During Step In it Comes on Me.PrintForm.error comes automatically Printer Error .How should I Catch this error???.let me know please .the following code logically Seems to be Ok !!!.
    Code:
    Public Sub BtPrint_Click()
    On Error GoTo errHnd
    If Err.Number = 482 Then
        MsgBox ("Printer is Not Ready ")
        Exit Sub
    End If
    Me.PrintForm
    Exit Sub
    errHnd:
    MsgBox Err.Description
    End Sub
    
    Attached Images Attached Images  

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Printer Issue

    Try to print AFTER the ON ERROR is set. Then, the ERROR TRAP IF Statement

    (No error BEFORE you try to print)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Re: Printer Issue

    The Problem is Simple When I Do Step In(F8) .when it Comes on Me.PrintForm .when I again Press F8 .It even Does Not Go To Next Line . and giving Error No 482 . How should I Trap this Printer Error Message .???if it Even does not go to next line when I press F8.Let me know the Idea .Any help would be highly appreciated.

  11. #11
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,345

    Re: Printer Issue

    Your error handler goes in the area at the bottom not before you try the thing that gives an error. Also you must set your IDE to break on unhandled errors only if you do not want it to throw an error within the IDE while debugging and have it use your error handler instead.

    Code:
    Sub Sample()
    
    On Error Goto ErrTrap:
    
    'Do some stuff 
    
    Exit Sub
    
    ErrTrap:
    If err.Number=53
       Msgbox "File not found"
    Else
       Msgbox Err.Description
    end if
    
    End Sub
    Always use [code][/code] tags when posting code.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)