- Joined
- Apr 25, 2008
- Messages
- 3
- Reaction score
- 0
I am writing an Access application for work. I have the whole thing up and running just lovely *except* trying to do customised error trapping. Please could someone evaluate the code below and give me a clue where i'm going wrong?
I am trying to trap error 3022 (that record already exists), so that if a user tries to input a record that would duplicate values, then they are given a msgbox asking if they want to edit the existing record, if yes, then go to the record; if not, clear the form and go to a new record. the 'no' part of this error trap i understand and have not yet coded. The problem i'm having is in the recordset.findfirst section.... The code falls at the line coloured red (it gives a 3022 error...)
Code is below
Private Sub Command11_Click()
On Error GoTo ErrorHandler
Me.Refresh
CleanUpAndExit:
Exit Sub
ErrorHandler:
Select Case Err.Number
Case 3022
Call MsgBox("That record already exists." & vbCrLf & _
"Do you want to edit the record?", vbYesNo)
If VbMsgBoxResult.vbYes Then
Dim rst As DAO.Recordset
Dim strFull As String
strFull = "[nameFull] = '" & Me.nameFull.Value & "'"
Set rst = Me.RecordsetClone
Me.Undo
rst.FindFirst (strFull)
Me.Bookmark = rst.Bookmark
Else
MsgBox ("boo")
End If
End Select
Call MsgBox("Error Code: " & Err.Number & ", " & Err.Description)
Resume CleanUpAndExit
End Sub
I am trying to trap error 3022 (that record already exists), so that if a user tries to input a record that would duplicate values, then they are given a msgbox asking if they want to edit the existing record, if yes, then go to the record; if not, clear the form and go to a new record. the 'no' part of this error trap i understand and have not yet coded. The problem i'm having is in the recordset.findfirst section.... The code falls at the line coloured red (it gives a 3022 error...)
Code is below
Private Sub Command11_Click()
On Error GoTo ErrorHandler
Me.Refresh
CleanUpAndExit:
Exit Sub
ErrorHandler:
Select Case Err.Number
Case 3022
Call MsgBox("That record already exists." & vbCrLf & _
"Do you want to edit the record?", vbYesNo)
If VbMsgBoxResult.vbYes Then
Dim rst As DAO.Recordset
Dim strFull As String
strFull = "[nameFull] = '" & Me.nameFull.Value & "'"
Set rst = Me.RecordsetClone
Me.Undo
rst.FindFirst (strFull)
Me.Bookmark = rst.Bookmark
Else
MsgBox ("boo")
End If
End Select
Call MsgBox("Error Code: " & Err.Number & ", " & Err.Description)
Resume CleanUpAndExit
End Sub