Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    6

    Unanswered: (Access) Clearing a field after validation rule pop-up window

    Hello,

    I have a form in which there are fields that have validation rules for the quantity and types of characters that are entered by the people on the production floor. The operators are wanting me to refine this so that if they accidentally enter or scan the wrong information, the affected field will automatically be cleared of the previously-entered contents (after they clear the validation error pop-up window). How can I accomplish this?

    Thanks

  2. #2
    Join Date
    Jan 2009
    Location
    Kerala, India
    Posts
    183
    Execute a statement similar to the following:

    Me![FirstName] = Me.[FirstName].OldValue

    to remove the wrong value and restore the old value.

    or

    If the user made changes in more than one field and want to undo it, either press Ctrl+Z by the user or execute the following code through a Command Button click:

    Code:
    Private Sub Command17_Click()
    If Me.Dirty Then
       Me.Undo
    End If
    End Sub
    Last edited by apr pillai; 06-29-12 at 13:52.
    www.MsAccessTips.com (Learn MS-Access Tips & Tricks)
    Learn Advanced MS-Access Programming with sample VBA Code.

    All responses are based on Access 2003/2007

  3. #3
    Join Date
    May 2012
    Posts
    6
    I tried out your recommended code, and I understand your intent of the code; but I actually want to keep all of the other current fields on the form as-is....I just want to only clear the entered text that relates specifically to the field that had the validation error.

    For example, on the top of my form the operators enter their shift number, part number and other credentials. Then lower down on the form, there are two fields to enter serial number and "Pass/Fail". If they accidentally scan the wrong barcode for the serial number field, or accidentally type in the wrong character on the "Pass/Fail" field, I want this incorrect information to automatically be deleted after they acknowledge the validation pop-up screen. However, the info entered above (shift number, part number, etc.) needs to remain static. Thanks in advance.

  4. #4
    Join Date
    Jan 2009
    Location
    Kerala, India
    Posts
    183
    This is what exactly what I meant by the first example (restoring the old status of the field when the entered value is wrong).

    Instead of setting up the validation rule in the property sheet write code in the lost_focus() Event procedure of the field to pop up a message when the entered value is not acceptable and to restore the old status of the field.

    Example:

    Code:
    Sub quantity_lost_focus()
    If me![quantity] < 1 or me![quantity]>100 then
       msgbox "Valid Value Range: 1 - 100"
       Me![Quantity] = Me.[Quantity].OldValue
    End If
    End Sub
    This will only reset the Quantity field.
    www.MsAccessTips.com (Learn MS-Access Tips & Tricks)
    Learn Advanced MS-Access Programming with sample VBA Code.

    All responses are based on Access 2003/2007

Posting Permissions

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