Hi All,
The code listed below does what it should. It checks for existing records in 2 fields an then allows for 3 options:
1. Yes - Existing found, add duplicate (2 John Smiths)
2. No - Open existing record
3. Cancel - Cancel and Undo
However after the code runs I get a message "no current record" message.
debugging shows that the problem happens after the me.undo before the If Not Me.RecordsetClo ne.NoMatch Then (Highlighted in bold in the code below). If I Remove the Me.Undo, I get a run-time error:
run-time error '2115': "The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Trading Places Guest Database from saving the data in the field"
I do not have enough coding experience to know how to fix this, and so am asking for help.
I am using Office Pro 2013 on Windows 8.
Thank you,
Dave
I would like to credit: TheSmileyCoder who wrote the original code.
And thank zmbd and NeoPa from this forum and TheDBGuy and Tina T from utteracces who have all helped so far.
The code listed below does what it should. It checks for existing records in 2 fields an then allows for 3 options:
1. Yes - Existing found, add duplicate (2 John Smiths)
2. No - Open existing record
3. Cancel - Cancel and Undo
However after the code runs I get a message "no current record" message.
debugging shows that the problem happens after the me.undo before the If Not Me.RecordsetClo ne.NoMatch Then (Highlighted in bold in the code below). If I Remove the Me.Undo, I get a run-time error:
run-time error '2115': "The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Trading Places Guest Database from saving the data in the field"
I do not have enough coding experience to know how to fix this, and so am asking for help.
I am using Office Pro 2013 on Windows 8.
Thank you,
Dave
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Check that no user exists with the same name
'Only perform check for new records
If Me.NewRecord Then
Dim lngUserCount As Long
lngUserCount = Nz(DCount("*", "[tblGuests]", _
"[FirstName]=""" & Me![FirstName] & _
""" AND [LastName]=""" & Me![LastName] & """"))
If lngUserCount > 0 Then
Dim intReply As VbMsgBoxResult
intReply = MsgBox("Guest Name Already Exists!" & vbNewLine & _
"Click 'Yes' to Add Duplicate," & vbNewLine & _
"Click 'No' open Existing Guest Record" & vbNewLine & _
"Click 'Cancel' to Discard All Changes", vbYesNoCancel + vbExclamation)
Select Case intReply
Case vbYes
'Allow save
Cancel = False
Case vbNo
'Stop the save
Cancel = True
'find the first value that matches
Me.RecordsetClone.FindFirst "[FirstName] = """ & Me![FirstName] & _
""" AND [LastName] = """ & Me![LastName] & """"
[B]Me.Undo[/B]
Forms!frmGuests.FirstName.SetFocus
'see if record was found
If Not Me.RecordsetClone.NoMatch Then
'move to record
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
Case vbCancel
'Stop the save and undo the form
Cancel = True
Me.Undo
MsgBox "Add a New Guest or Select the Existing Guest From the 'Lookup Guest' Function."
Forms!frmGuests.FirstName.SetFocus
End Select
End If
End If
End Sub
And thank zmbd and NeoPa from this forum and TheDBGuy and Tina T from utteracces who have all helped so far.
Comment