ensure fields are filled

R

Rachael

Hi I would like to ensure all fields on the form are
filled before a user exits the db?

I have a quit button on my form and it is there for
people to exit entirely from access. I need to validate
the form and display a message if not all fields are
filled. This way i will safeuard against any bad records
and so i need the button to check that either all fields
are filled or none are filled as the only way for the
button to work.

Thanks

Rachael
 
N

Newbie

You need to setup up a validation procedure
Something like:
In the on click event of your exit button
Private Sub Command2_Click()
Dim lvalid As Long

lvalid = validation()
If lvalid = False Then
Exit Sub
Else
DoCmd.Close
End If

End Sub

Function validation()
validation = False
If Nz(Me.Text0.Value, "") = "" Then
Me.Text0.SetFocus
Exit Function
end if
validation = True
End Function

'the validation function would be the place for you to put all your checks
for the form

Hope this helps
 
Top