I am adding records chosen from as list box to a table using a command button. Inevitably users will try to add duplicates to this table. The table uses a dual key of API and ContactName.
When I try to create my own message box to replace the error message for err 3022 the code hangs on [highlight].update [/highlight]and does NOT got to my err handler. What's wrong here and what is the fix?
When I try to create my own message box to replace the error message for err 3022 the code hangs on [highlight].update [/highlight]and does NOT got to my err handler. What's wrong here and what is the fix?
Code:
Private Sub cmd_AddWellContacts_Click()
On Error GoTo Err_cmd_AddWellContacts_Click
Dim API As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim item As Integer
Dim Cri, LBx As ListBox, itm, Build As String, DQ As String
Set LBx = Forms![Main Form]![lst_SelectWellContacts]
Set db = CurrentDb
Set rs = db.OpenRecordset("data_WellContacts")
With rs
For Each itm In LBx.ItemsSelected
.AddNew
!API = API
!Contacts_ID = LBx.Column(0, itm)
!ContactPosition = LBx.Column(1, itm)
!ContactName = LBx.Column(2, itm)
!ContactInitials = LBx.Column(3, itm)
!ContactWorkPhone = LBx.Column(4, itm)
!ContactCellPhone = LBx.Column(5, itm)
!ContactHomePhone = LBx.Column(6, itm)
!ContactEmail = LBx.Column(7, itm)
!OperationsGroup = LBx.Column(8, itm)
!DateCreated = Now()
!UserCreated = fOSUserName()
[highlight].Update 'hangs here[/highlight]
.Bookmark = rs.LastModified
Next
End With
rs.Close
Me.Refresh
Forms![Main Form]![frm_Wellcontacts subform].Form.Requery
'
Exit_cmd_AddWellContacts_Click:
Set db = Nothing
Exit Sub
Err_cmd_AddWellContacts_Click:
MsgBox Err.Description
Select Case Err.Number
Case 3022
MsgBox (Err.Number & "One or More of your Selections are Already Contacts for the Selected Well" _
& "Please Edit Contact Selection and Try Again!")
MsgBox Err & vbCrLf & Error$, , "Error"
End Select
Resume Exit_cmd_AddWellContacts_Click
End Sub