Hello
I have a set of Navigation buttons (Move First, Move Next, Move Previous, Move Last). Sometimes after a record was deleted,, the Error "2105 You can't go to the specified record" occurs, and sometimes it just jumps to a new record (showing a blank empty form like it's ready for entering new record).What was the possible cause ? How do I fix the error? If the"If err.number = 2105 then Resume ExitProcedure" was added in the ErrorHandler section, will the work or appropriate? Below is my code.Thanks
Phucon
Private Sub cmdDelContract_Click()
On Error GoTo ErrorHandlerCall FindFormRecord(Me, "ConId", Me.txtConID) Me.cboSearchCon.RequeryExitProcedure: Exit SubErrorHandler: MsgBox "Error Number: " & Err.Number & vbNewLine _ & "Error Describtion: " & Err.Description & " in procedure cmdDelContract_Click." Resume ExitProcedure ResumeEnd SubPrivate Sub cmdNext_Click()
On Error GoTo ErrorHandlerSet rs = Me.RecordsetCloneIf Not rs.EOF Then MoveNextElse MovePreviousEnd IfExitProcedure: rs.Close Exit SubErrorHandler: MsgBox Err.Number & vbCrLf & Err.Description Resume ExitProcedure ResumeEnd SubSub MoveNext()On Error GoTo ErrorHandlerDoCmd.GoToRecord record:=acNextMoveNext_Exit:Exit SubErrorHandler:MsgBox "Error Number: " & Err.Number & vbCrLf & _ "Error Description: " & Err.Description & " in procedure MoveNext."End Sub'Find the record and delete it.
Public Function FindFormRecord(SearchForm As Access.Form, SearchField As String, SearchValue As Variant, Optional NoMatchMessage As String = "Record not found") As BooleanOn Error GoTo ErrorHandlerWith SearchForm.RecordsetClone Select Case .Fields(SearchField).Type Case dbText SearchValue = Chr$(34) & SearchValue & Chr$(34) Case dbLongSearchValue = SearchValue End Select
If Not .EOF Then .FindFirst "[" & SearchField & "] = " & SearchValue If Not .NoMatch Then 'if found then delete the record. If MsgBox("You are deleting this record. " & vbCrLf & "Proceed to delete?", vbInformation + vbYesNo, "Confirm Delete") = vbYes Then.Delete
End If Else
MsgBox NoMatchMessageGoTo ExitDelete
End If
Else
GoTo ExitDeleteEnd IfEnd WithExitDelete:
Exit FunctionErrorHandler: MsgBox Err.Number & vbCrLf & Err.Description Resume ExitDelete
End Function
Posted by: saigonf7q5@yahoo.com
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (1) |
Tidak ada komentar:
Posting Komentar