-----Original Message-----
Susy,
Yes there are ways to do all these things.
But I will save you (and your users) a lot of heartache - there is no need
to do any of them.
========================================================== ==========
You can use a procedure like this to validate as many controls as you like
before the record is saved. Note: you don't always have to set Cancel =True.
Your validation could include checking for Null values and simply filling
them in with a "default" value in your code.
If everything passes the validation, there will be no message box because
Cancel will be False and the record will save.
If anything fails, then Cancel will be True and the user will see the
problem and can fix it and try to save the record again.
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
Dim strMessage As String
If Me![txt1] < 0 Or Me![txt2] > 100 Then
strMessage = strMessage & vbCrLf & "Value must be between 0 and 100."
Cancel = True
End If
If Left$(Me![txtTableName], 3) = "tbl" Then
strMessage = strMessage & vbCrLf & "New table names cannot start with
tbl."
Cancel = True
End If
If IsNull(Me![EmailAddress]) Then
strMessage = strMessage & vbCrLf & "Please enter an E- mail address
before saving the record."
Cancel = True
End If
If Cancel = True Then
MsgBox (strMessage)
End If
Exit_Form_BeforeUpdate:
Exit Sub
Err_Form_BeforeUpdate:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source &
vbCrLf & Err.Description, , "FormName - Form_BeforeUpdate"
Resume Exit_Form_BeforeUpdate
End Sub
--
Joe Fallon
Access MVP
Can I lock a field when a user clicks it?
That is, is it possible to set up a form with a yes/no
field that, if clicked, restricts the user from going any
farther until he enters data in some required fields?
I have the form and I've done conditional formatting to
hide the fields until the box is clicked, plus I've added
a message box to prompt the user to enter the data, but I
can't MAKE him actually enter the data.
Is there a way to do this?
Thanks.
.