Results 1 to 8 of 8
  1. #1
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101

    Question Replace standard error message with a custom error message

    Run-time error 2101: The setting you entered isn't valid for this property.

    I want it to be replaced with a custom error message.

    Is this the right code? It is not working for me.

    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Select Case DataErr


    Case 2101
    MsgBox "MY CUSTOM MESSAGE"
    Response = acDataErrContinue
    End Select
    Active Control.Undo
    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Try:
    Code:
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Select Case DataErr
    Case 2101
      MsgBox "MY CUSTOM MESSAGE"
      Response = acDataErrContinue
    End Select
    
    Me.ActiveControl.Undo
    
    End Sub
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    It is still not working. I continue to get the error.

    Do I have to replace ActiveControl with anything else?

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Check that your code does actually fire.
    Are you sure you are testing for the correct error number.

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I would test to see if it's even getting to your subform error function, it might have to be a public function to fire from the subform.

    Have you tried doing the error trapping on the form itself instead?

    i.e.
    Code:
    ON ERROR goto OMGWHATHAPPENED
    .... your code here
    
    
    OMGWHATHAPPENED:
    debug.print err.number & err.description
    select case err.number
    case 2101
        'error handling for 2101 here
    case XXXX
    
    Case Else
    
    End Select

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    You're referring to the ActiveControl, but this error (the setting you entered isn't valid for this property) pops when you're attempting to set a property of a Control or other object, in code...not during data entry, which kind of sounds like your objective, here.

    Are you, perhaps, wanting to change the error message if inappropriate data is entered in a Control...i.e. entering Text in a Number Field?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    Quote Originally Posted by Bob Fitz View Post
    Check that your code does actually fire.
    Are you sure you are testing for the correct error number.
    This could be the reason. I assumed that the number carried in the error message is the error number. Am I right?
    If I am wrong, how can I find the actual error number of the error?

  8. #8
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    @Missinglinq

    This error pops up when I click a button on my form. See here: Error while switching forms

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

Similar Threads

  1. Replies: 5
    Last Post: 05-15-2015, 10:49 AM
  2. Replies: 15
    Last Post: 11-01-2013, 03:24 PM
  3. custom error message
    By msasan1367 in forum Access
    Replies: 1
    Last Post: 04-27-2013, 09:14 AM
  4. Replies: 1
    Last Post: 03-25-2012, 01:53 PM
  5. Custom error message problem
    By thekruser in forum Programming
    Replies: 10
    Last Post: 10-06-2010, 05:14 PM

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