Rabu, 27 Agustus 2014

Re: [MS_AccessPros] Error 2015 You can’t go to the specified record

 

Phucon-


The problem is you're deleting the record out from under the form, so the recordset of the form gets out of sync.  You could try using With SearchForm.Recordset instead of RecordsetClone.  When you use RecordsetClone, that's a *copy* of the form's recordset, not what the form is using.

If you know the form containing the record you want to delete has the focus when your delete code runs, you could do:

    RunCommand acCmdSelectRecord
    DoCmd.SetWarnings False
    RunCommand acCmdDelete
    DoCmd.SetWarnings True

That does the delete in the User Interface, so the form knows what it needs to do after the record disappears.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Aug 28, 2014, at 12:01 AM, saigonf7q5@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

  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 ErrorHandler
   Call FindFormRecord(Me, "ConId", Me.txtConID) 
   Me.cboSearchCon.Requery

ExitProcedure:   
   Exit 

SubErrorHandler:     
    MsgBox "Error Number: " & Err.Number & vbNewLine _      
           & "Error Describtion: " & Err.Description & " in procedure cmdDelContract_Click."   
    Resume ExitProcedure    
     Resume
End Sub

Private Sub cmdNext_Click()

On Error GoTo ErrorHandler
Set rs = Me.RecordsetClone
If Not rs.EOF Then
    MoveNext
Else 
   MovePrevious
End If

ExitProcedure: 
   rs.Close
  Exit Sub

ErrorHandler: 
  MsgBox Err.Number & vbCrLf & Err.Description
   Resume ExitProcedure
   Resume
End Sub

Sub MoveNext()
On Error GoTo ErrorHandler

DoCmd.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 Boolean

On Error GoTo ErrorHandler

With SearchForm.RecordsetClone
    Select Case .Fields(SearchField).Type 
       Case dbText
             SearchValue = Chr$(34) & SearchValue & Chr$(34)
       Case dbLong 
             SearchValue = 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 NoMatchMessage

               GoTo ExitDelete

            End If

Else

    GoTo ExitDelete
End If
End With

ExitDelete:

    Exit Function

ErrorHandler:        MsgBox Err.Number & vbCrLf & Err.Description

        Resume ExitDelete

End Function



 


 

  

 

             

__._,_.___

Posted by: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

.

__,_._,___

Tidak ada komentar:

Posting Komentar