Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2019
    Posts
    20

    Using a command button to clear all fields in a form after data validation error has been generated


    I have a form containing multiple required textboxes with data validation. I have created custom validation messages. Currently, if a user enters an invalid value, the message will appear, telling them to enter an acceptable value. The user cannot navigate elsewhere until they enter a valid value.

    Also on the form, I have a button that clears the current record. I would like the form to work in such a way that if a data validation error is generated, the user has the option of clicking the clear button to clear all fields in the record. Currently, if a validation error is generated and the user attempts to click the clear button, the validation error will appear, forcing the user to enter a value. The user could hit the ESC key to clear the textbox, but I'm building this form for people who wouldn't know about the ESC key, and I would prefer to not have to educate them.

    Any suggestions for how to set this up?

    Thanks!

  2. #2
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    Hmm, perhaps coding your Clear buttons to...

    Code:
    If Me.YourControl <> "" Then
         Me.YourControl .Undo
         Cancel = True
    End If
    ...will work.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,811
    Me.Undo will clear the whole form. I only read mention of one button, not many
    clear button to clear all fields in the record.
    but you can undo every control one by one as suggested if that's not the case.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 7
    Last Post: 01-28-2019, 04:33 AM
  2. Creating a Form Button to Clear Table Data
    By wojosh6 in forum Access
    Replies: 5
    Last Post: 12-10-2015, 01:45 PM
  3. Replies: 3
    Last Post: 05-16-2012, 10:20 AM
  4. table generated command button????
    By crabbymcdo in forum Forms
    Replies: 1
    Last Post: 06-24-2011, 04:11 AM
  5. Command button code to clear form
    By windwardmi in forum Forms
    Replies: 15
    Last Post: 11-21-2010, 03:21 PM

Tags for this Thread

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