Debug Run-Time Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • littleclayjar
    New Member
    • Jun 2007
    • 2

    #1

    Debug Run-Time Error

    On a filter form, I have three search criteria. When i click the button to "Clear Selection", I get a 'Run-time error '3021 - No current record' if any one of the criteria has not been selected. So for example, if I have Country and Packaging selected but not Technology and i want to clear all the filters, then the RunTime error comes up. What am I missing in the code?

    Here is what i have for the code so far:

    Private Sub cmdDeSelectAll_ Click()
    Dim rsCountryDest As DAO.Recordset
    Dim rsTechnologyDes t As DAO.Recordset
    Dim rsPackagingDest As DAO.Recordset

    'Clear all Country filters

    Set rsCountryDest = Me.Lst_Countrie s_Dest.Recordse t
    rsCountryDest.M oveFirst

    Do While Not rsCountryDest.E OF
    rsCountryDest.E dit
    rsCountryDest!I nSelectedList = False
    rsCountryDest.U pdate
    rsCountryDest.M oveNext
    Loop

    Me.Lst_Countrie s_Source.Requer y
    Me.Lst_Countrie s_Dest.Requery
    rsCountryDest.C lose

    'Clear all Technology filters

    Set rsTechnologyDes t = Me.Lst_Technolo gy_Dest.Records et
    rsTechnologyDes t.MoveFirst

    Do While Not rsTechnologyDes t.EOF
    rsTechnologyDes t.Edit
    rsTechnologyDes t!InSelectedLis t = False
    rsTechnologyDes t.Update
    rsTechnologyDes t.MoveNext
    Loop

    Me.Lst_Technolo gy_Source.Reque ry
    Me.Lst_Technolo gy_Dest.Requery
    rsTechnologyDes t.Close

    'Clear all Packaging filters

    Set rsPackagingDest = Me.Lst_Packagin g_Dest.Recordse t
    rsPackagingDest .MoveFirst

    Do While Not rsPackagingDest .EOF
    rsPackagingDest .Edit
    rsPackagingDest !InSelectedList = False
    rsPackagingDest .Update
    rsPackagingDest .MoveNext
    Loop

    Me.Lst_Packagin g_Source.Requer y
    Me.Lst_Packagin g_Dest.Requery
    rsPackagingDest .Close

    End Sub

    Thanks for the help in advance!
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    Originally posted by littleclayjar
    On a filter form, I have three search criteria. When i click the button to "Clear Selection", I get a 'Run-time error '3021 - No current record' if any one of the criteria has not been selected. So for example, if I have Country and Packaging selected but not Technology and i want to clear all the filters, then the RunTime error comes up. What am I missing in the code?

    Here is what i have for the code so far:

    Private Sub cmdDeSelectAll_ Click()
    Dim rsCountryDest As DAO.Recordset
    Dim rsTechnologyDes t As DAO.Recordset
    Dim rsPackagingDest As DAO.Recordset

    'Clear all Country filters

    Set rsCountryDest = Me.Lst_Countrie s_Dest.Recordse t
    rsCountryDest.M oveFirst

    Do While Not rsCountryDest.E OF
    rsCountryDest.E dit
    rsCountryDest!I nSelectedList = False
    rsCountryDest.U pdate
    rsCountryDest.M oveNext
    Loop

    Me.Lst_Countrie s_Source.Requer y
    Me.Lst_Countrie s_Dest.Requery
    rsCountryDest.C lose

    'Clear all Technology filters

    Set rsTechnologyDes t = Me.Lst_Technolo gy_Dest.Records et
    rsTechnologyDes t.MoveFirst

    Do While Not rsTechnologyDes t.EOF
    rsTechnologyDes t.Edit
    rsTechnologyDes t!InSelectedLis t = False
    rsTechnologyDes t.Update
    rsTechnologyDes t.MoveNext
    Loop

    Me.Lst_Technolo gy_Source.Reque ry
    Me.Lst_Technolo gy_Dest.Requery
    rsTechnologyDes t.Close

    'Clear all Packaging filters

    Set rsPackagingDest = Me.Lst_Packagin g_Dest.Recordse t
    rsPackagingDest .MoveFirst

    Do While Not rsPackagingDest .EOF
    rsPackagingDest .Edit
    rsPackagingDest !InSelectedList = False
    rsPackagingDest .Update
    rsPackagingDest .MoveNext
    Loop

    Me.Lst_Packagin g_Source.Requer y
    Me.Lst_Packagin g_Dest.Requery
    rsPackagingDest .Close

    End Sub

    Thanks for the help in advance!
    In each of the recordsets, you are doing a moveFirst without checking for RecordCount <> 0 , or alternatively, that .EOF or .BOF is not true.

    See item #3 on the following link entitled VBA Traps Working With Recordsets
    Common mistakes developers make when working with Recordsets in a Microsoft Access database

    Comment

    • littleclayjar
      New Member
      • Jun 2007
      • 2

      #3
      Thank you very much! It worked!

      Comment

      Working...