FORMS - all fields filled out

  • Thread starter Thread starter kealaz
  • Start date Start date
K

kealaz

Is there anyway to insure that each and every field is filled in, before
allowing record to be saved and form to be closed. If a field is missed I
would like some type of error message to pop up.

Thanks!
 
You would use the form's BeforeUpdate event to run code that verifies that
all required data have been provided, and if not, cancel the save of the
data.

Sample code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.NameOfControl1.Value & "") = 0 Then
MsgBox "You must fill in data for 'name of control or data'!", _
vbOK, "Missing Data"
Cancel = True
Me.NameofControl1.SetFocus
If Len(Me.NameOfControl2.Value & "") = 0 Then
MsgBox "You must fill in data for 'name of control or data'!", _
vbOK, "Missing Data"
Cancel = True
Me.NameofControl2.SetFocus
If Len(Me.NameOfControl3.Value & "") = 0 Then
MsgBox "You must fill in data for 'name of control or data'!", _
vbOK, "Missing Data"
Cancel = True
Me.NameofControl3.SetFocus
End If
End Sub
 
Back
Top