Form Validation

G

Guest

I have tried using this code on my form to trap Required fields being left
empty. It does not work properly though, it is a continuous form - could this
cause a problem?

Three of my text boxes have a Tag of Reqd, values for them have to be
entered before a record can be saved. Even if I fill in all three fields
though I can not save the record, it prompts with the 'Value Required' text?

Thanks
Sue

Dim ctl As Control

For Each ctl In Me.Section(0).Controls

If ctl.Tag = "Reqd" Then
If Len(Trim(Nz(ctl, vbNullString))) Then
MsgBox ctl.name & " Requires A Value", vbExclamation + vbOKOnly
Cancel = True
ctl.SetFocus
Exit For
End If
End If

Next
 
G

Guest

Excellent thanks that did the trick ;-). Sorry, copied code from another
example which had that bit missing.

Thanks again
Sue
 

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