Results 1 to 11 of 11
  1. #1
    Benj is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    33

    how to eliminate validation rule error message

    Good day! two error messages pops up everytime I entered a wrong value into a field... first would be the VALIDATION TEXT MESSAGE then the "THE VALUE VIOLATES THE VALIDATION RULE FOR FIELD RECORD"... how do i eliminate the 2nd one? thanks in advance!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    remove the validation rule from the field.
    put validation on the form (or not)

  3. #3
    Benj is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    33
    my validation rule is for a DATE that should be equal to or more than another date. how do i place that on the form? thanks in advance ranman256

  4. #4
    Benj is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    33
    got it! thanks!

  5. #5
    Benj is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    33
    follow-up ranman256. i tried the code on the form (afterupdate, msgbox). the problem is, it would go to the next field even if there's an error. what would be the code so that it wont go to the next field? like if msg = vbYes then...

    thanks!

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I think you'd have to post the code to get an answer.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    On the form you do the validations in the BeforeUpdate event that can be canceled (Cancel=True) to force the user to enter the right value.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    Benj is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    33
    sorry am a newbie... how can i cancel it? my code is

    Private Sub PDate_BeforeUpdate(Cancel As Integer)




    If Me.PDate < [Forms]![Main]![subdate] Then
    MsgBox ("Date is BEFORE the inital date, please change the date")
    End If
    If Me.PDate > [Forms]![Main]![endDate] Then
    MsgBox ("Date is AFTER the last date, please change the date")
    End If
    End Sub

    i even tried

    dim ans as string

    ans = MsgBox ("Date is BEFORE the inital date, please change the date", vbOk)

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    something like
    Code:
    If Me.PDate < [Forms]![Main]![subdate] Then
     MsgBox ("Date is BEFORE the inital date, please change the date")
     Cancel = True
     Me.PDate.SetFocus
     Exit Sub
    End If
    
    If Me.PDate > [Forms]![Main]![endDate] Then
     MsgBox ("Date is AFTER the last date, please change the date")
     Cancel = True
     Me.PDate.SetFocus
     Exit Sub
    End If
    
    End Sub
    Although Cancel seems to expect an integer, True is commonly used because it equates to -1.
    Please use code tags and indentation to make your code easier to read.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    Benj is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    33
    Good day Micron! i tried your code, it gives me an error message "Run-time error 2108" you must save the field before you execute the GoToControl action, the GoToControl method or the SetFocus method.

    thanks in advance!

    p.s. I remove the Me.PDate.SetFocus and it is doing what I intend it to do! thanks so much!

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You're welcome. Perhaps I made some assumptions as to what event this was for, or whatever else was going on that you didn't post. My intention was to return the user to the offending control if they had set focus somewhere else, but I was guessing that this was even happening. Glad you got it fixed.

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

Similar Threads

  1. Replies: 4
    Last Post: 12-05-2017, 03:31 PM
  2. Replies: 2
    Last Post: 06-16-2015, 03:52 AM
  3. Replies: 2
    Last Post: 01-11-2014, 03:56 PM
  4. Validation Rule
    By noob123 in forum Access
    Replies: 1
    Last Post: 12-02-2013, 03:39 PM
  5. Custom validation error message
    By snorkyller in forum Access
    Replies: 2
    Last Post: 03-21-2011, 03:40 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