Hi
When adding a person to a contacts form I'm checking for existence of the same name already in the contacts table.
I've added the code below as a BeforeUpdate procedure on the forms's LastName field, where qryCheckName is a simple query taking the form's FirstName and LastName fields as criteria.
If a user says no to adding the person I want the form to be cleared but the code below fails on trying to set me.LastName = Null.
It says the 'macro or function set to the BeforeUpdate or Validation rule property for this field is preventing Access from saving the data in the field'.
There's no validation rule and can't see why it objects to the LastName field being set to null when setting the FirstName to null is ok.
Or maybe there's an easier way of clearing all the fields in the form?
****************
If DCount("*", "qryCheckName") < 1 Then
Exit Sub
End If
Dim stDocName As String
stDocName = "frmCheckName"
DoCmd.OpenForm stDocName
If MsgBox("OK to add new person?", vbYesNo) = vbNo Then
DoCmd.Close acForm, "frmCheckName"
Me.FirstName = Null
Me.LastName = Null
Cancel = True
Else
DoCmd.Close acForm, "frmCheckName"
End If
When adding a person to a contacts form I'm checking for existence of the same name already in the contacts table.
I've added the code below as a BeforeUpdate procedure on the forms's LastName field, where qryCheckName is a simple query taking the form's FirstName and LastName fields as criteria.
If a user says no to adding the person I want the form to be cleared but the code below fails on trying to set me.LastName = Null.
It says the 'macro or function set to the BeforeUpdate or Validation rule property for this field is preventing Access from saving the data in the field'.
There's no validation rule and can't see why it objects to the LastName field being set to null when setting the FirstName to null is ok.
Or maybe there's an easier way of clearing all the fields in the form?
****************
If DCount("*", "qryCheckName") < 1 Then
Exit Sub
End If
Dim stDocName As String
stDocName = "frmCheckName"
DoCmd.OpenForm stDocName
If MsgBox("OK to add new person?", vbYesNo) = vbNo Then
DoCmd.Close acForm, "frmCheckName"
Me.FirstName = Null
Me.LastName = Null
Cancel = True
Else
DoCmd.Close acForm, "frmCheckName"
End If