Results 1 to 9 of 9
  1. #1
    Reaper is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Nov 2011
    Posts
    57

    Need to capture when user tries to save an empty record


    I have a data entry form that has a "SAVE" and "CANCEL" button. I want to capture the fact that the user has clicked save without adding data. The table has an autonumber field.

    Is there a way to test for the empty autonumber field? The field displays (NEW) before any inputs are made. I've tried using IsNull, checking for the value 0, checking for zero length, empty "", etc. without success.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Why not disable/hide the SAVE button until you check and vaerify that the fields that need to be valued have in fact been valued
    In the before update event of the form, review each control on the form and ensure those that need values, have values.

    Just typing while reading your post.

  3. #3
    Reaper is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Nov 2011
    Posts
    57
    So the SAVE button is unavailable until all the required fields have input... Can you clarify a bit? What event would trigger the code to check for this? A timer event? Seems like it would need to be run over and over until it was happy. In general I'm intrigued. Never thought of that before.

    My usual method is to check each required field after the SAVE button is pushed and prompt the user to make the input...or cancel the form. Today I was setting up a new form and thought, "What if we bypass all that when the user tries to save a blank form and just close it?" Since the Autonumber doesn't populate until any input is made I thought that would be quick and dirty. Anyway, that's how the train of thought started.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I would use your method of checking each field, but I would include that in the BeforeUpdate event of the form.

    There may be times where the user enters a field then backs out -- that could still be an issue.
    May be someone else has more detail.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by orange View Post

    ...I would include that in the BeforeUpdate event of the form...
    As orange said, you really have to do this kind of validation in the Form_BeforeUpdate event. In this event, if the validation fails, you can use

    Cancel = True

    to cancel the update, but this is not available in the OnClick event of a Command Button.

    Linq ;0)>

  6. #6
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    What event would trigger the code to check for this?
    Suppose you had the following fields:
    Tb1, Tb2, Tb3 which must not be empty then you can insert a code in the after update event of each of the fields like this:
    Code:
    If (me.Tb1.value = Null) or (Me.Tb2 = Null) or (Me.Tb3 = Null) Then
        me.CmdSave.Enable = False
    Else 
        Me.CmdSave.Enable = True
    End if

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Two things, here:

    Quote Originally Posted by Demerit View Post

    ...you can insert a code in the after update event of each of the fields...
    You cannot place code used to validate that a given Field is populated in the AfterUpdate event of that Field; all that's needed to defeat the test is to simply ignore the Field, i.e. not even enter it; if no data is entered, the AfterUpdate event doesn't execute! The AfterUpdate event, of a given Field, should only be used to check the validity of data that is actually entered into the Field, i.e. is it Numeric, if it is supposed to be, or a valid Date, etc. As has already been said, validation used to test if a Field is actually populated has to be done in the Form_BeforeUpdate event.

    Quote Originally Posted by Demerit View Post

    If (me.Tb1.value = Null) or (Me.Tb2 = Null) or (Me.Tb3 = Null) Then
    While

    If me.Tb1.value = Null

    is correct syntax for some languages, even SQL in Access, for instance, in VBA Code, it has to be

    If IsNull(me.Tb1.value)

    Linq ;0)>

  8. #8
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    If me.Tb1.value = Null is correct syntax for some languages, even SQL in Access, for instance, in VBA Code, it has to be If IsNull(me.Tb1.value)
    Thanks for the correction Missinglinq really messed up there
    You cannot place code used to validate that a given Field is populated in the AfterUpdate event of that Field
    The idea here is simply to ensure that all the fields actually have a value. Be it Text, date/Time, Number ..... Does not matter If all the fields have a value then the CmdSave is then enabled. This will ensure that a user does delete a value entered in a previous textbox because doing that will disable the command save button. This is why the verification can only be done in after update event of the field. For correction of the code above it will actually look like this:
    Code:
     If Not IsNull(me.Tb1) or Not IsNull (Me.Tb2) or Not IsNull (Me.Tb3) Then     me.CmdSave.Enable = True Else      Me.CmdSave.Enable = False End if

  9. #9
    Reaper is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Nov 2011
    Posts
    57
    So, the SAVE command button simply closes the form. All the code to check for empty fields is in the BEFORE_UPDATE event code, if empty fields exist, use CANCEL=TRUE to back out of the update and go back to the form. Is that it in a nutshell?

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

Similar Threads

  1. Replies: 7
    Last Post: 09-11-2014, 12:26 PM
  2. how to Capture Individual User who made entries in form
    By bronson_mech in forum Programming
    Replies: 2
    Last Post: 08-19-2013, 10:07 AM
  3. Replies: 1
    Last Post: 10-25-2012, 08:24 AM
  4. Replies: 3
    Last Post: 10-08-2012, 08:40 AM
  5. Replies: 8
    Last Post: 09-27-2012, 11:12 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