Results 1 to 4 of 4
  1. #1
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159

    How to handle error messages?

    I have the following code (below) that I use to allow the user to select a particular value to determine which records to delete. However, I was wondering if there was a way to avoid having the Microsoft Access auto-generated messages pop up.

    For this particular case, after the user selects the value and hits the command button, then a msg box comes up verifying if the user wants to delete the records with selected value. Clicking 'Yes' will then generate the Access message that asks the user again if they want to delete the records and that these actions can not be undone. Clicking Yes here will delete the records.



    However, clicking 'No' or x'ing off this Access generated message will then cause a Run-time error 2501. I want to handle this error if it all possible.




    Code:
    Private Sub CmdRemove_Click()
        Dim strQuery As String
        
        DoCmd.Beep
        If vbYes = MsgBox("Are you sure you want to delete? Clicking 'Yes' will completely remove all prospects with the selected Class from the database", vbYesNo + vbQuestion, "Delete prospects?") Then
        strQuery = "DELETE * FROM [Prospects] " & "WHERE Prospects.Class = '" & Forms("Classpopup").cmbRemove & "';"
        DoCmd.RunSQL strQuery
        End If
        
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    So you want the warning messages? Sounds like you want to trap for the error:

    http://www.baldyweb.com/ErrorTrap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Quote Originally Posted by pbaldy View Post
    So you want the warning messages? Sounds like you want to trap for the error:

    http://www.baldyweb.com/ErrorTrap.htm
    Yes. Thank you kind sir.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Best way to handle this Web Database
    By tucker1003 in forum Database Design
    Replies: 8
    Last Post: 03-18-2011, 12:14 PM
  2. 'handle' command
    By B Mellars in forum Access
    Replies: 6
    Last Post: 12-14-2010, 01:23 PM
  3. Custom messages to Access' default error messages.
    By evander in forum Programming
    Replies: 1
    Last Post: 06-26-2010, 02:06 AM
  4. What is the best way to handle photos?
    By TundraMonkey in forum Database Design
    Replies: 2
    Last Post: 08-12-2009, 10:52 PM
  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