scapegoat17
scapegoat17

Reputation: 5841

MS Access table validation

I was wondering if anybody would be able to tell me how to check if multiple fields in a form are valid or not. Basically I want to set up a validation rule for my last field to check if all of the previous fields are blank or not.

I have already tried this:

IsNull([FieldName])

I know that this is only for one field, but I can't even get that to work. I am pretty new with access so any help would be much appreciated. Thank you!

Upvotes: 0

Views: 103

Answers (1)

blushRedTail
blushRedTail

Reputation: 81

What i would do is in the tag property for each control you want to validate, put a word in there that you can check for (example - enter "VALIDATE" for each control you want checked). To find the tag property: look at the property sheet for each control, in the OTHER tab, the last field listed = tag).

Then as code in the afterupdate event of the last control, select EVENT PROCEDURE and enter this code:

Dim ctl As Control

For Each ctl In Forms!YourFormName
If ctl.Tag = "validate" Then
    If IsNull(ctl.Value) Then
        ctl.SetFocus
        MsgBox "You must complete the " & ctl.Name & " field.", vbOKOnly, "Required Field Missing"
        GoTo exitsub
    End If 
End If
Next

exitsub:
Exit Sub

If this finds and empty field, it will move back to that field, (set focus) and display a message box that states they must enter a value.

Upvotes: 1

Related Questions