S
SelfTaught
While attempting to insert a duplicate record into an indexed field using the
DoCmd.OpenForm method after clicking on a command button I, of course,
receive a key violation warning. Based on that warning, I would like to open
a form that lists all of the records rather than attempting to insert that
duplicate record. So in other words, I would like to test for a duplicate
record and then take appropriate action based on if a duplicate is found or
not found. What is the best way to accomplish this? This is my current code
and I think that I've gone about this the wrong way from the beginning:
Private Sub Command26_Click()
On Error GoTo Err_Command26_Click
Dim stDocName As String
Dim stDocName2 As String
Dim stLinkCriteria As Date
Dim stDocName3 As String
Dim DataErr As Integer
stDocName = "CurrentPeriodEntry"
stDocName2 = "Main Menu"
stDocName3 = "EditPeriodEntry"
stLinkCriteria = Forms![Main Menu]!Text28
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, stDocName2
Exit_Command26_Click:
Exit Sub
Err_Command26_Click:
If DataErr = 3022 Then
DoCmd.OpenForm stDocName2
DoCmd.Close acForm, stDocName2
Else
MsgBox Err.Description
End If
End Sub
DoCmd.OpenForm method after clicking on a command button I, of course,
receive a key violation warning. Based on that warning, I would like to open
a form that lists all of the records rather than attempting to insert that
duplicate record. So in other words, I would like to test for a duplicate
record and then take appropriate action based on if a duplicate is found or
not found. What is the best way to accomplish this? This is my current code
and I think that I've gone about this the wrong way from the beginning:
Private Sub Command26_Click()
On Error GoTo Err_Command26_Click
Dim stDocName As String
Dim stDocName2 As String
Dim stLinkCriteria As Date
Dim stDocName3 As String
Dim DataErr As Integer
stDocName = "CurrentPeriodEntry"
stDocName2 = "Main Menu"
stDocName3 = "EditPeriodEntry"
stLinkCriteria = Forms![Main Menu]!Text28
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, stDocName2
Exit_Command26_Click:
Exit Sub
Err_Command26_Click:
If DataErr = 3022 Then
DoCmd.OpenForm stDocName2
DoCmd.Close acForm, stDocName2
Else
MsgBox Err.Description
End If
End Sub