Hello everyone!
I have created a form named "DuplicateName", which I would like to use instead of a messageBox. This form will be ran from the results of a BeforeUpdate event of a form called "ParticipantInfo". I would like the buttons of the DuplicateName form to perform the following actions to ParticipantInfo
Yes: Save the Record
No: Cancel Record from Saving
Cancel: Stop the record from saving and allow you to continue editing the form
List: Open up a Report
I know how to do the VBA for the List button.. I just used the OpenReport method. But how do I perform the Yes/No/Cancel actions? This is the code I have so far.
What is happening in this first line of code is we are comparing the First and Last name of a participant to existing users in "tblParticipantInfo". If there is a participant with the same name it will cause the DuplicateName form to open.
And this is the VBA code for the click event of each of the buttons on the DuplicateNames form
I hope someone can help me on this. I appreciate all advice.
Thank you
I have created a form named "DuplicateName", which I would like to use instead of a messageBox. This form will be ran from the results of a BeforeUpdate event of a form called "ParticipantInfo". I would like the buttons of the DuplicateName form to perform the following actions to ParticipantInfo
Yes: Save the Record
No: Cancel Record from Saving
Cancel: Stop the record from saving and allow you to continue editing the form
List: Open up a Report
I know how to do the VBA for the List button.. I just used the OpenReport method. But how do I perform the Yes/No/Cancel actions? This is the code I have so far.
What is happening in this first line of code is we are comparing the First and Last name of a participant to existing users in "tblParticipantInfo". If there is a participant with the same name it will cause the DuplicateName form to open.
Code:
[COLOR=green]' Check to see if there is a possible duplicate name in the database[/COLOR]
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim lngUserCount As Long
[COLOR=green]' Only perform check for new records[/COLOR]
If Me.NewRecord Then
lngUserCount = DCount("*", "[tblParticipantInfo]", _
"[PFirstName]='" & Me.PFirstName & "' AND " & _
"[PLastName]='" & Me.PLastName & "'")
If lngUserCount > 0 Then
DoCmd.OpenForm ("DuplicateName")
End If
End If
End Sub
And this is the VBA code for the click event of each of the buttons on the DuplicateNames form
Code:
Option Compare Database
Private Sub cmdYes_Click()
[COLOR=green]' Allow Save[/COLOR]
End Sub
Private Sub cmdNo_Click()
[COLOR=green]' Stop the Save[/COLOR]
End Sub
Private Sub cmdCancel_Click()
[COLOR=green]' Stop the Save and undo the form[/COLOR]
End Sub
Private Sub cmdList_Click()
[COLOR=green]' Open a list of possible duplicate participants[/COLOR]
DoCmd.OpenReport "rptDupNames", acViewPreview
End Sub
I hope someone can help me on this. I appreciate all advice.
Thank you