form field constraints

  • Thread starter Thread starter dtm
  • Start date Start date
D

dtm

I have a form that has a text box i would like to require to be filled when
i click a submit button.

If i put constraints into the rule validation field it only validates when
you tab or click on that text box. I want to validate the constraints when a
command button is press. Can someone give me some guidance on how to code
constraint checking? thanks.
 
To prevent the record being saved if a particular field is left blank, open
your table in design view, and set the field's Required property to Yes.

You can also do it by setting the the Validation Rule of the field in the
table to:
Is Not Null

If you want to conditionally validate (i.e. warn the user if it is left
blank, but allow them to override the warning and save it anyway), use the
BeforeUpdate event procedure of the *form* (not text box). As you found, the
text box's events are not triggered if nothing is entered there.
 
Ok, this didn't quite do what i wanted so i put an if/then in there that
did. upon clicking the button, i just did an if blank then error box and
jump to the end w/o saving the data.

Now, can someone tell me how i can evaluate a field to be a specific number
of characters? I have a field that is 8 digits alpha numberic. setting the
constraints in the table just aren't working.

dm.
 
The form events are inferior to the table rules, because they are only
applied if the entry is made through the form.

But if you want it:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Nz(Me.[NameOfYourTextBoxHere], vbNullString)) <> 8 Then
Cancel = True
MsgBox "Exactly 8 characters required."
End If
End Sub
 
Back
Top