saving data on a form

Jon123

Registered User.
Local time
Today, 14:41
Joined
Aug 29, 2003
Messages
668
Is there a simple way to make sure all fields on a form are filled before the data is saved to the table? I looked into using thew IF is Null Then but for 30 fields that is alot of code. Does anyone know a easier way?

Jim
 
One big IF OR statement.

IF IsNull(txt1) Or IsNull(txt2)..... Then
MsgBox "Not all fields filled in!"

etc.

Cant really think of another way of checking for blank fields without the IF OR statement.
 
You must use the forms BeforeUpdate event to perform your validation code.

You can simply use an IF as suggest but you also have to test for empty strings.

Code:
If IsNull(MyField) or MyField = "" Then

The below might be more efficient...
Code:
Key "Required" in the Tag property of the form object.

    Dim ctl As Control
    For Each ctl In Me
        If ctl.Tag = "Required" Then
            If IsNull(ctl) Or ctl = "" Then
                MsgBox "You must complete all required fields to continue", vbCritical, "Required Field"
                ctl.SetFocus
                Exit Sub
            End If
        End If
    Next
    Set ctl = Nothing
 

Users who are viewing this thread

Back
Top Bottom