There's this part of my program that I'm trying to 'catch' the user if in case he/she is trying to add a new record with an ID that already exists in the database before he/she hits the save button and it won't work..
Here's my code:
Private Sub cmdSave_Click() GetRS Set rs = Nothing rs.CursorLocation = adUseClient If Mode = "New" Then rs.Open "SELECT COUNT(e_ID) As noDUP FROM Employee WHERE e_ID = '" & txtEmpID & "'",cn,3,2 If noDUP = 0 Then rs.AddNew Else MsgBox ("Record Already Exists!") Exit Sub End If ElseIf Mode = "Edit" Then rs.Open "Select * from Employee where e_Id ='" & txtEmpID & "'", cn, 3, 2 End If With rs .Fields(0) = txtEmpID .Fields(1) = txtFirst .Fields(2) = txtLast .Fields(3) = Val(cmbDept) .Fields(4) = txtOffice .Fields(5) = txtHome .Fields(6) = dtpDateHired.Value .Fields(7) = CDbl(txtHourlyRate) .Update End With Locked_Fields End Sub
I'm getting an error message that says "item cannot be found in the collection corresponding to the requested name or ordinal"