Hi There
When a user adds a new record (or edits an existing one) I generate a checksum value (based upon a number of fields) and use it in the 'Before Update' event to check that a duplicate record is not being created.
If the Checksum already exists, then I want to undo the addition/update and take the user to the existing record.
<code>
If MyCheck <> "" Then
MyRecNo = DLookup("ID_CMTY_Address", "QRY_ADDRESS_Maintenance", "AddrChecksum = '" & MyCheck & "'") ' I get an error here
If MyRecNo > 0 Then 'Checksum already exists, therefore this is a duplicate record.
MyMsg = MsgBox("It seems that this address already exists." & vbCr _
& "the changes that you have made will be undone." & vbCr _
& "Do you wish to go to the existing record?", vbYesNo, "ADDRESS EXISTS")
Me.Undo
Cancel = True
If MyMsg = 7 Then
DoCmd.GoToRecord acDataForm, "Frm_Admin_Address", acGoTo, MyRecNo
End If
End If
</code>
I'm getting an error on the DLOOKUP line - I suspect that its because the checksum contains +,-,/ and = signs in it, but I am encasing this in single quotes.
The form is bound to "QRY_ADDRESS_Maintenance"
Can you see that I have missed something?
The next part of the problem related to the "DoCmd.GoToRecord"
1. Surely I want to move to the record pointer, not necessarily the record id (ID_CMTY_Address)?
So how do I DLookup the record pointer and what DoCmd do I need to use?
2. The user is able to filter the form - How will this affect the above?
When a user adds a new record (or edits an existing one) I generate a checksum value (based upon a number of fields) and use it in the 'Before Update' event to check that a duplicate record is not being created.
If the Checksum already exists, then I want to undo the addition/update and take the user to the existing record.
<code>
If MyCheck <> "" Then
MyRecNo = DLookup("ID_CMTY_Address", "QRY_ADDRESS_Maintenance", "AddrChecksum = '" & MyCheck & "'") ' I get an error here
If MyRecNo > 0 Then 'Checksum already exists, therefore this is a duplicate record.
MyMsg = MsgBox("It seems that this address already exists." & vbCr _
& "the changes that you have made will be undone." & vbCr _
& "Do you wish to go to the existing record?", vbYesNo, "ADDRESS EXISTS")
Me.Undo
Cancel = True
If MyMsg = 7 Then
DoCmd.GoToRecord acDataForm, "Frm_Admin_Address", acGoTo, MyRecNo
End If
End If
</code>
I'm getting an error on the DLOOKUP line - I suspect that its because the checksum contains +,-,/ and = signs in it, but I am encasing this in single quotes.
The form is bound to "QRY_ADDRESS_Maintenance"
Can you see that I have missed something?
The next part of the problem related to the "DoCmd.GoToRecord"
1. Surely I want to move to the record pointer, not necessarily the record id (ID_CMTY_Address)?
So how do I DLookup the record pointer and what DoCmd do I need to use?
2. The user is able to filter the form - How will this affect the above?