List all missed fields in one msgbox

morlan

Registered User.
Local time
Today, 16:19
Joined
Apr 23, 2003
Messages
143
Hi,

I've been looking though the search and can't seem to find anything.
I have fields on my form that must be filled before the user can add a record.
If the user tries to add a record, and the required fields are not filled, they will get a popup message box for each missed field.
What would be the best way of listing all the missed fields in one message box?

eg.

You have not completed the following fields:

Name
Birth Date
City


Cheers
 
Try using the BeforeUpdate event of the form. In the code, have a string variable that contains the names of all the unfilled controls. Add to the list like this:
Code:
Dim ctl as Control
Dim strMissedControls as String

For Each ctl in Me.Controls
    If ctl.Value="" Then
        strMissedControls=strMissedControls & vbCrLf & ctl.Name
    End If
Next ctl

If strMissedControls <> "" Then
    strMissedControls= "You have not completed the following fields:" & strMissedControls
    Cancel=True
End If
Be sure to check all my syntax. I just typed it in.
 
Thanks dcx, that's a much better way of doing it!
 

Users who are viewing this thread

Back
Top Bottom