Hi
I have a form where customers are entered. I want to ensure the same customer is not given 2 references so am divising a bit of code to check. I have created a field on the form that strings together the Surname and UPRN. I have then created a qry which does the same and gives a count of how many exist in the table.
I no want to apply validation to all the aspects. I can get them to work fine individually, but cannot seem to work out how to get all three working together.
I first want to check a surname has been entered. Then I want to check a UPRN has been entered. Finally I want to check the check2 control against the qry to look for duplicates.
I have tried nesting the if statements, and running them one after hte other, but what ever i try the form either stays open when i want to shut it, or saves the new entry when i dont want it to.
This is what i have at the moment running from a close button (I have disabled the native close button on the form):
I have a form where customers are entered. I want to ensure the same customer is not given 2 references so am divising a bit of code to check. I have created a field on the form that strings together the Surname and UPRN. I have then created a qry which does the same and gives a count of how many exist in the table.
I no want to apply validation to all the aspects. I can get them to work fine individually, but cannot seem to work out how to get all three working together.
I first want to check a surname has been entered. Then I want to check a UPRN has been entered. Finally I want to check the check2 control against the qry to look for duplicates.
I have tried nesting the if statements, and running them one after hte other, but what ever i try the form either stays open when i want to shut it, or saves the new entry when i dont want it to.
This is what i have at the moment running from a close button (I have disabled the native close button on the form):
Code:
Private Sub Command40_Click()
'check surname is present
If IsNull(Me![ClientSurname]) Then
If MsgBox("'Client Surname' must contain a value." & Chr(13) & Chr(10) & _
"Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
"Press 'Cancel' to abort the record.", _
vbOKCancel, "A Required field is blank") = vbCancel Then
DoCmd.Close
Else
Me![ClientSurname].SetFocus
End If
End If
'check address is present
If IsNull(Me![AddressUPRN]) Then
If MsgBox("'Address' must contain a value." & Chr(13) & Chr(10) & _
"Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
"Press 'Cancel' to abort the record.", _
vbOKCancel, "A Required field is blank") = vbCancel Then
DoCmd.Close
Else
Me![Command39].SetFocus
End If
End If
'check no duplicate
If DCount("*", "qryCheckDuplicate", "check='" & Me.check2 & "'") > 0 Then
MsgBox ("this is a duplicate entry and will not be saved")
Me.Undo
DoCmd.Close
Else
DoCmd.Close
End If
End Sub