Hi,
I am New to Access and have very little coding experience.
I am trying to modify the code (see below) posted by TheSmileyCoder on this site.
Basically, the code checks for existing records. 3 options are given:
1. Save new record
2. Duplicate found go to that the record
3. Cancel and Undo
Option 2. returns a runtime error:2115 and the debugger highlights the line "Me.Bookmar k = Me.RecordsetClo ne.Bookmark"
From what I have read the problem has to do with saving the record. But I have no idea how to fix this. I would like the code to open the existing record in the form.
Can someone help?
Thank you,
Dave Rapson
I am New to Access and have very little coding experience.
I am trying to modify the code (see below) posted by TheSmileyCoder on this site.
Basically, the code checks for existing records. 3 options are given:
1. Save new record
2. Duplicate found go to that the record
3. Cancel and Undo
Option 2. returns a runtime error:2115 and the debugger highlights the line "Me.Bookmar k = Me.RecordsetClo ne.Bookmark"
From what I have read the problem has to do with saving the record. But I have no idea how to fix this. I would like the code to open the existing record in the form.
Can someone help?
Thank you,
Dave Rapson
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 "[LastName]= '" & LastName & "'" '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 DoCmd.RunCommand acCmdUndo MsgBox "Add a New Guest or Select the Existing Guest From the 'Lookup Guest' Function." End Select End If End If End Sub
Comment