Results 1 to 18 of 18

Thread: current recordset does not support scrolling backward

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    current recordset does not support scrolling backward

    im going to delete a record but i encounter an error of current recordset does not support scrolling backward..
    here's my code
    Code:
    Private Sub cmdDelete_Click()
    With tbDepartment
    ans = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait")
            If ans = vbYes Then
               .Find "DepartmentName = '" & txtDepTitle.Text & "'"
                If .EOF = True Then
                    MsgBox "Huh?"
                Else
                    .Delete
                    .Requery
                    txtDepTitle = ""
                End If
            Else
                Refresh
            End If
    End With
    End Sub
    
    Private Sub cmdGetDepartment_Click()
    PickDepartment.Show
    PickDepartment.cmdSelect.Visible = False
    End Sub
    
    Private Sub cmdCancel_Click()
    Unload Me
    End Sub
    
    Private Sub Form_Load()
    tbdepartment.open "Select * from tbdepartment", cn. adopendynamic, adloackoptimistic
    end sub

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: current recordset does not support scrolling backward

    Is this "adloackoptimistic" really in your code or just a pasting error?

  3. #3
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: current recordset does not support scrolling backward

    I think it's adLockOptimistic.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: current recordset does not support scrolling backward

    also i believe should be comma after cn, not period
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: current recordset does not support scrolling backward

    Private Sub cmdDelete_Click()
    With tbDepartment
    ans = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait")
    If ans = vbYes Then
    .Find "DepartmentName = '" & txtDepTitle.Text & "'"
    If .EOF = True Then
    MsgBox "Huh?"
    Else
    .Delete
    .Requery
    txtDepTitle = ""
    End If
    Else
    Refresh
    End If
    End With
    End Sub

    Private Sub cmdGetDepartment_Click()
    PickDepartment.Show
    PickDepartment.cmdSelect.Visible = False
    End Sub

    Private Sub cmdCancel_Click()
    Unload Me
    End Sub

    Private Sub Form_Load()
    Set tbDepartment = Nothing
    dept = "Select * from tbdepartment where DepartmentName like '" & txtDepTitle.Text & "'"
    tbDepartment.Open dept, cn, adOpenDynamic, adLockOptimistic

    End Sub

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: current recordset does not support scrolling backward

    Try this
    VB Code:
    1. rivate Sub cmdDelete_Click()
    2. With tbDepartment
    3. ans = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait")
    4.         If ans = vbYes Then
    5.            .Find "DepartmentName = '" & txtDepTitle.Text & "'"
    6.             If .EOF = True Then
    7.                 MsgBox "Huh?"
    8.             Else
    9.                 .Delete
    10.                   [B] ' .Requery[/B] 'Comment this line and run
    11.                 txtDepTitle = ""
    12.             End If
    13.         Else
    14.             Refresh
    15.         End If
    16. End With
    17. End Sub
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: current recordset does not support scrolling backward

    it was running now but it always show the msgbox. and the .EOF is always true

    VB Code:
    1. Private Sub cmdDelete_Click()
    2. 'Set tbDepartment = Nothing
    3. 'dept = "Select * from tbdepartment where DepartmentName like '" & txtDepTitle.Text & "'"
    4. 'tbDepartment.Open dept, cn, adOpenDynamic, adLockOptimistic
    5.  
    6. tbDepartment.Open "Select * from tbdepartment", cn, adOpenDynamic, adLockOptimistic
    7.  
    8. With tbDepartment
    9. ans = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait")
    10.         If ans = vbYes Then
    11.            .Find "DepartmentName = '" & txtDepTitle.Text & "'"
    12.             If .EOF = True Then
    13.                 MsgBox "Huh?"
    14.             Else
    15.                 .Delete
    16.               '  .Requery
    17.                 txtDepTitle = ""
    18.             End If
    19.         Else
    20.             Refresh
    21.         End If
    22. End With
    23. End Sub

  8. #8
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: current recordset does not support scrolling backward

    I think you can try this method
    VB Code:
    1. Private Sub cmdDelete_Click()
    2. 'Set tbDepartment = Nothing
    3. 'Dim tbDepartment As New ADODB.Recordset
    4. 'dept = "Select * from tbdepartment where DepartmentName like '" & txtDepTitle.Text & "'"
    5. 'tbDepartment.Open dept, cn, adOpenDynamic, adLockOptimistic
    6.  
    7.  
    8.  
    9.  
    10.     If MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait") = vbYes Then
    11.             tbDepartment.Open "Select * from tbdepartment where DepartmentName='" & txtDepTitle.Text & "'", cn, adOpenDynamic, adLockOptimistic
    12.             If tbDepartment.EOF = False Then
    13.                  tbDepartment.Delete adAffectCurrent
    14.              Else
    15.                 MsgBox "Huh?"
    16.                  txtDepTitle = ""
    17.              End If
    18.            
    19.     End If
    20. End Sub
    Please mark you thread resolved using the Thread Tools as shown

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: current recordset does not support scrolling backward

    whats the use of adaffectcurrent

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: current recordset does not support scrolling backward

    still not working and have the same error

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: current recordset does not support scrolling backward

    it was running now thank you

  12. #12
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: current recordset does not support scrolling backward

    Try this also
    VB Code:
    1. Private Sub cmdDelete_Click()
    2. 'Set tbDepartment = Nothing
    3. 'Dim tbDepartment As New ADODB.Recordset
    4. 'dept = "Select * from tbdepartment where DepartmentName like '" & txtDepTitle.Text & "'"
    5. 'tbDepartment.Open dept, cn, adOpenDynamic, adLockOptimistic
    6.  
    7.  
    8.  
    9.  
    10.     If MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait") = vbYes Then
    11.             'tbDepartment.Open "Select * from tbdepartment where DepartmentName='" & txtDepTitle.Text & "'", cn, adOpenDynamic, adLockOptimistic
    12.             cn.Execute ("Delete * from tbdepartment where DepartmentName='" & txtDepTitle.Text & "'")
    13. '            If tbDepartment.EOF = False Then
    14. '                 tbDepartment.Delete adAffectCurrent
    15. '             Else
    16. '                MsgBox "Huh?"
    17. '                 txtDepTitle = ""
    18. '             End If
    19.            
    20.     End If
    21. End Sub
    Please mark you thread resolved using the Thread Tools as shown

  13. #13
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: current recordset does not support scrolling backward

    Running Now ?
    Please mark you thread resolved using the Thread Tools as shown

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: current recordset does not support scrolling backward

    how about this one.... when i'm adding a new data and my table is empty i always encounter the .eof or .bof is closed or deleted. how can i avoid this even if my table is empty

  15. #15
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: current recordset does not support scrolling backward

    VB Code:
    1. tbDepartment.Open "Select * from tbdepartment where 1<>1", cn, adOpenDynamic, adLockOptimistic
    2. tbDepartment.addnew
    3. 'Do your additions
    4. tbDepartment.update
    Please mark you thread resolved using the Thread Tools as shown

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: current recordset does not support scrolling backward

    in all my tables when i' going to add i have to this code same with other tables
    VB Code:
    1. tbDepartment.Open "Select * from tbdepartment where 1<>1", cn, adOpenDynamic, adLockOptimistic
    2. tbDepartment.addnew
    3. 'Do your additions
    4. tbDepartment.update

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: current recordset does not support scrolling backward

    i still have the same error either .eof or .bof is true, or current recordset has been deleted. requested operation requires a record... this the error i always got when that table is empty

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: current recordset does not support scrolling backward

    The Find method requires you to initialize the recordset with a .Movexxxxx call. Either MoveFirst or MoveLast depending on the search direction you will be performing.

    You can pass the argument of adSearchForward or adSearchBackwards. Depending on the direction of the search, if no matching record is found then the rs will be positioned at either the BOF or EOF.

    I personally dont like using Find as its just creates more work/code to use when you can just call the delete action in a sql statement call. The call will still be made to the db with the Find plus you will have to execute the delete too so by passing the "DELETE Table1 FROM Table1 WHERE SomeField = 'Something'" is preferred.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width