CopperWire
Technical User
How do I handle an error within the append query? I know the error that I want to handle is conDuplicateKey = 3022, which is a duplicate key error, but I don't know how to reference this error. Can I even do this is a DoCmd command? My code is below, any help would be great!
Private Sub SaveBtn_Click()
VarDeptIDResult = IIf(IsNull(DeptId), "True", "False")
If (VarDeptIDResult = True) Then
MsgBox "Please enter a DeptID - Record was NOT saved.", vbOKOnly, "Missing DeptID"
GoTo 1:
End If
On Error GoTo Err_Command84_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String
stDocName = "AppendQuery"
DoCmd.OpenQuery stDocName, acNormal, acEdit
'MsgBox "Save Successful", vbOKOnly, "It Worked!"
Exit_Command84_Click:
Exit Sub
Err_Command84_Click:
MsgBox "This record already exists", vbOKOnly, "Record Not Saved"
'MsgBox Err.Description
Resume Exit_Command84_Click
1
End Sub
Private Sub SaveBtn_Click()
VarDeptIDResult = IIf(IsNull(DeptId), "True", "False")
If (VarDeptIDResult = True) Then
MsgBox "Please enter a DeptID - Record was NOT saved.", vbOKOnly, "Missing DeptID"
GoTo 1:
End If
On Error GoTo Err_Command84_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String
stDocName = "AppendQuery"
DoCmd.OpenQuery stDocName, acNormal, acEdit
'MsgBox "Save Successful", vbOKOnly, "It Worked!"
Exit_Command84_Click:
Exit Sub
Err_Command84_Click:
MsgBox "This record already exists", vbOKOnly, "Record Not Saved"
'MsgBox Err.Description
Resume Exit_Command84_Click
1
End Sub