FORMS - all fields filled out

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!
 
K

Ken Snell [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top