Results 1 to 4 of 4
  1. #1
    BDevil15 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2013
    Posts
    10

    Form validation before saving

    I have a simple form with a save button created directly from a table. I would like the on click event to check 4 fields to be sure that they weren't left blank and have a msgbox prompting to fill in the missing data, obviously not saving until all fields are complete. Fields are FirstName LastName Age Position. If all data is filled I would like the button to save the record and begin new record. Very new to VBA.



    Thanks for any help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Options:

    1. set the fields as required in the table and let Access nag the users if not filled in

    2. code in form BeforeUpdate event
    If IsNull([FirstName]) Or IsNull([LastName]) Or IsNull([Age]) Or IsNull([Position]) Then
    Cancel = True
    End If

    People grow. Really should save date of birth, not age, and calculate age when needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    You could use this:
    Code:
    If IsNull(me.FirstName) Then 
        Msgbox "Please provide the FirstName"     
       Me.FirstName.SetFocus
    Elseif IsNull(Me.LastName) Then     
       Msgbox "Please provide the LastName" 
        Me.LastName.SetFocus 
    ElseIf IsNull(Me.Position) Then 
        Msgbox "Please enter the position" 
        Me.Position.SetFocus ElseIf IsNull(Me.Age) Then 
        MsgBox "Please enter the age"
         Me.Age.SetFocus
    End if
    As June7 said preferably you store DOB than Age
    Last edited by June7; 08-30-2014 at 10:27 AM.

  4. #4
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,035
    Hi,

    use the BeforeUpdate event of the form to check all fields that should be filled and build a message string to inform them of all missing info at once. Users tend to dislike having a message telling them to fill in one box and after filling this information having a new message telling them to fill the other box too.

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

Similar Threads

  1. Replies: 10
    Last Post: 10-22-2013, 07:35 AM
  2. saving records on a form
    By trailerdoctor in forum Forms
    Replies: 1
    Last Post: 04-15-2013, 11:02 PM
  3. saving a form
    By Ray67 in forum Forms
    Replies: 11
    Last Post: 10-23-2011, 06:45 PM
  4. Prevent Saving of Form
    By bburton in forum Access
    Replies: 4
    Last Post: 02-25-2011, 09:26 PM
  5. Closing and saving a form
    By Lxmanager in forum Forms
    Replies: 14
    Last Post: 11-21-2010, 02:04 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