Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2005
    Posts
    12

    Unanswered: Prevent Empty Fields In A Record

    Hello,

    What's the best approach to preventing users from leaving empty fields in a record.

    Here's the scenario:

    A user fills in two of four fields on a form and decides to complete the remaining fields some other time.

    Here's the problem:

    One of the empty fields is the name field. So now I have this saved record but can't identify who it belongs too since the name field is blank.


    Can anyone give a coding example on how to prevent this kind of problem. I'm open to all suggestions at this point since I'm not good at programming VB.

    Thanks in advance

  2. #2
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Well, the easiest (not necessarily best) way is to do this is to set the field properties on the Table to not allow zero length and make it required. This will cause an error message if the field is null or empty.

    This would be the "Code Free" method. I suggest getting into VBA though, since use of these properties may cause heartburn down the road.

    Good luck
    have fun!

    Todd S.
    click to email


    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET


    _________________________________________________
    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  3. #3
    Join Date
    Nov 2003
    Posts
    1,487
    Here is a quick sample. Place this code into your Form's Before Update event:
    Code:
    Dim Ctrl As Control
    For Each Ctrl In Me.Controls
       If Ctrl.ControlType = acTextBox Or Ctrl.ControlType = acComboBox Then
    	  If IsNull(Ctrl) = True Then
    		 MsgBox "Whoa...Hey...You didn't fill in all the data " & _
    				"fields for this record. Please do so now.", _
    				vbExclamation, "** Fill'em Up Will Ya **"
    		 Cancel = True
    		 Exit For
    	  End If
       End If
    Next Ctrl
    There ya go...

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  4. #4
    Join Date
    Jun 2005
    Posts
    12
    CyberLynx,

    Awesome, your code works perfectly. Thanks a million because I could not have coded this myself.

    Thanks also to Todd for your reply

Posting Permissions

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