Results 1 to 12 of 12
  1. #1
    sanal is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    43

    Error code to prevent error messages

    I have used event proceedure in a click event of a button to open a report. Sometime certain error messages are occurred due to certain wrong user input such as null value in a field. I have tried to use my own error handlers in the code but not succeeded. Hence will you please inform me the correct code to suppress the system error messages and to show my own error messages such as "Avoid null value in the field..."etc.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Prevent the bad input.

    Set fields as Required in table.

    Use ValidationRule and ValidationText properties.

    Validate data input before record committed table.

    Validate user inputs for filter criteria before opening report.

    For error handler, review http://allenbrowne.com/ser-23a.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    sanal,

    Further to June's good advice, I recommend you do some searching google and/or youtube for Examples of Error Handling with Access vba

    Paul Kelly has a great article of VBA Error Handling. He is an Excel guru, but the material is applicable to vba--so is relevant to Access.

    Error handling by Allen Browne.

  4. #4
    sanal is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    43
    THANK YOU for the advice. As per your directions the error handler I created is as follows.Now it seems to be working but I am not sure. Please verify the code and inform me your valuable suggestions. I have also used the No data event of the report to prevent the opening of the report if there is no data.

    Private Sub Command138_Click()
    On Error GoTo Err_Command138_Click

    DoCmd.OpenReport "Bill59C", acViewPreview
    Exit_Command138_Click:
    Exit Sub
    Err_Command138_Click:
    Select Case Err.Number
    Case 440
    Resume Next
    Case Else
    MsgBox Err.Description, vbDefaultButton1, "PF TAP"
    Resume Exit_Command138_Click
    End Select

    End Sub

    I eagerly waiting for your suggestions and help. Thanks in advance.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    You should use code tags when posting code.
    Your code will be easier to read and debug and maintain if you do some consistent indenting.ms access error 440

    Code:
    Private Sub Command138_Click()
        On Error GoTo Err_Command138_Click
    
        DoCmd.OpenReport "Bill59C", acViewPreview
    Exit_Command138_Click:
        Exit Sub
    Err_Command138_Click:
        Select Case Err.number
        Case 440
            Resume Next
        Case Else
            MsgBox Err.Description, vbDefaultButton1, "PF TAP"
            Resume Exit_Command138_Click
        End Select
    
    End Sub
    What exactly is error 440? Why did you choose to Resume Next?

  6. #6
    sanal is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    43
    lam only a beginner in programming . I want to suppres the error messages related to the Error No.440. Please help me to rewrite the code.

  7. #7
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Error 440 is an "Automation error" - which I don't understand if you are simply opening a report.
    Remove the error handler and show us where it goes wrong in the code, If it's when it opens the report then show the code in the Report.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    As a general rule, you should only suppress error messages if you know they can be ignored without harm
    In the case of an automation error you definitely need to identify the cause

    Try opening the same report from the navigation pane. Does that work?
    Try opening another report (or form) from that button code. Does that work?

    Doing both of these will help identify whether the issue os the report itself (possibly corrupted) or the source form with the button code
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    sanal is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    43
    I have used a function in a textbox in the report to convert number to words. The error Occured when the reports has no data . There seem to be no harm if the error is ignored. Pl help me to rewrite the error handler to ignore the error.

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Suggest you add code to the NoData event in the report to manage that situation and/or add error handling to the number to words function e.g use Nz function
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    As Ridders suggests , you should fix the data issue in the function, not cludge around the result of the poor or missing data.
    This will make your process much more robust and is by far the best practice
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Prevent the bad input.

    If the issue is only some records do not have value in the field, as suggested, use Nz(): MyFunction(Nz([fieldname]))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error messages
    By Lou_Reed in forum Access
    Replies: 8
    Last Post: 12-08-2016, 11:34 PM
  2. Turn Off Error Messages for Printing
    By pdevito3 in forum Access
    Replies: 3
    Last Post: 09-24-2013, 02:15 PM
  3. How to handle error messages?
    By yes sir in forum Access
    Replies: 3
    Last Post: 10-15-2011, 11:22 AM
  4. Custom messages to Access' default error messages.
    By evander in forum Programming
    Replies: 1
    Last Post: 06-26-2010, 02:06 AM
  5. Error Messages
    By DataGeek in forum Access
    Replies: 0
    Last Post: 12-06-2007, 09:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums