Can you detect if the subform causes the code to fire and then bail out but
execute it for the main form?
==========================================================
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
Giannis Isaias said:
Hello everyone.
i 'd like to validate the data entered by a user when he/she exits the
current record. unfortunately the before update method is not appropreate
because the form updates 3 times while the user is in the current record so
because of a subform so this is not a good idea. I tried to use the
RecordExit event but it does nt seem to work at all.