Notify user of missing data on form closure

G

Guest

I have a form with many fields. Users on a network are allowed to create new
records or edit existing records in this form. I have 3 fields in the form
that must be filled in by the user so I can properly identify the issue. I
can set these fields to “Required†and that will prevent the user from
starting a second record until he has entered data into the 3 fields.
However if a user does not enter data into all 3 of these fields and simply
closes the form he will loose all the data he put into that record. How do
you code the close button to look at these three fields to see if their null
and if null return a message to add data or you will loose all the
information in the record.
 
G

Guest

Couple of ways...

The simple way is to set the Validation Rule and Validation Text proerties
for your fields. You can set the Rule to 'Not IsNull' and the Text property
to the message you want to display to the user if the rule is violated.

If that will not do, you will have to do it in code.
Create a Function like this:

Private Function ValidateFields() As Boolean
If Nz(Me.FieldName,"") = "" Then
MsgBox "Input Required!"
ValidateFields = False
Exit Function
End If

'Repeat for other fields

'If it gets this far, all fields have a value
ValidateFields = True
End Function

In your form's BeforeUpdate event:

If ValidateFields = False Then
Cancel = True
End If

Steve
 
G

Guest

Thanks Steve it worked great!! I did modify it slightly so that when the
Closed button has focus and ValidateFields are false then the unpopulated
field gets focus, otherwise the form just closes when I select the Close
button.
 

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