cRODEEkrank
Technical User
Hi,
I'm building a database which tracks the # of minutes a person spent working on a specified task. I created an Access form which will accept their input. The form is unbound, but I created a procedure to bind the controls when the user wants to save their information to the database.
My problem is, I'm trying to trap error #3022 which pops up if the user tries to enter a duplicate record. This error comes up when the "rs.update" command is executed. I've tried to trap this error, but for some reason it just won't trap it, and the standard Access error message displays.
Here's my code:
Private Sub BindControls()
Dim rs As DAO.Recordset
Dim strSQL As String
Dim intTaskID As Integer
Dim strEmpNum As String
On Error GoTo TrapErrors
strSQL = "SELECT TaskID FROM tblTaskLookup WHERE
TaskName='" & gstrTask & "';"
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset,
dbConsistent, dbPessimistic)
rs.AddNew
rs!TaskID = intTaskID
rs!EmployeeID = gstrEmployeeID
rs!Date = CDate(txtDate.Value)
rs!Comments = Nz(txtComments.Value, ""
rs!ProjectName = Nz(txtProjectName.Value, ""
rs!ContactName = Nz(txtContactName.Value, ""
rs!Minutes = CDbl(txtNumMinutes.Value)
rs!NumOfMaterials = CInt(Nz(txtMatGoodNums.Value, 0))
rs!SubTasks = Nz(cboSubtasks.Value, ""
rs!NumSets = CInt(Nz(txtNumSets.Value, 0))
rs.Update
'close, free recordset object:
rs.Close
Set rs = Nothing
Exit Sub
TrapErrors:
Select Case Err.Number
Case 3022
MsgBox "The system has indicated an entry for this date and task has already been entered into the database. Please go to the edit section to make any necessary changes to this task", vbOKOnly + vbExclamation, "Entry Already Exists for this Task"
End Select
End Sub
Help?
I'm building a database which tracks the # of minutes a person spent working on a specified task. I created an Access form which will accept their input. The form is unbound, but I created a procedure to bind the controls when the user wants to save their information to the database.
My problem is, I'm trying to trap error #3022 which pops up if the user tries to enter a duplicate record. This error comes up when the "rs.update" command is executed. I've tried to trap this error, but for some reason it just won't trap it, and the standard Access error message displays.
Here's my code:
Private Sub BindControls()
Dim rs As DAO.Recordset
Dim strSQL As String
Dim intTaskID As Integer
Dim strEmpNum As String
On Error GoTo TrapErrors
strSQL = "SELECT TaskID FROM tblTaskLookup WHERE
TaskName='" & gstrTask & "';"
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset,
dbConsistent, dbPessimistic)
rs.AddNew
rs!TaskID = intTaskID
rs!EmployeeID = gstrEmployeeID
rs!Date = CDate(txtDate.Value)
rs!Comments = Nz(txtComments.Value, ""
rs!ProjectName = Nz(txtProjectName.Value, ""
rs!ContactName = Nz(txtContactName.Value, ""
rs!Minutes = CDbl(txtNumMinutes.Value)
rs!NumOfMaterials = CInt(Nz(txtMatGoodNums.Value, 0))
rs!SubTasks = Nz(cboSubtasks.Value, ""
rs!NumSets = CInt(Nz(txtNumSets.Value, 0))
rs.Update
'close, free recordset object:
rs.Close
Set rs = Nothing
Exit Sub
TrapErrors:
Select Case Err.Number
Case 3022
MsgBox "The system has indicated an entry for this date and task has already been entered into the database. Please go to the edit section to make any necessary changes to this task", vbOKOnly + vbExclamation, "Entry Already Exists for this Task"
End Select
End Sub
Help?