• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1248
  • Last Modified:

Microsoft Access- FilterOn affects DoCmd.GoToRecord?

Dear Experts,
  This is pretty strange...  I have a form with a subform.  The users can click on cmdDown or cmdUp to go thru the list of employees.  This works fine and always has.
  There is a checkbox that allows a filter to be enabled or not.  If the checkbox is checked, we enabled a filter and only show employees with violations.  If it's not checked, we turn the filter off to see all employees.  This works fine and always has.
  Now I'm trying to add the feature: If we have scrolled down the list of employees and then turn the filter on or off, I don't want to go back to the beginning of the list.  I want to stay on or around the employee that I had scrolled down to.  (the list is in alphabetical order)  See the code below.  THE CODE WORKS FINE WHEN THE CHECKBOX IS CHECKED (FILTER IS ON) BUT IT BREAKS WHEN THE CHECKBOX IS UNCHECKED (FILTER IS TURNED OFF).  WHY IS THIS?  Does the FilterOn property enable/disable DoCmd.GotoRecord?  The error I get is: run-time error 2105  You can't go to the specified record
Any help is appreciated!
Private Sub cmdDown_Click()
    On Error Resume Next 'if it tries to go beyond the eof
    DoCmd.GoToRecord , , acNext
End Sub
 
Private Sub cmdUp_Click()
    On Error Resume Next 'if it tries to go before the beginning of file
    DoCmd.GoToRecord , , acPrevious
End Sub
 
Private Sub chkShowOnlyTardyEmployees_AfterUpdate()
    If chkShowOnlyTardyEmployees = True Then
        glvarTemp = Me!FullName
        Me.FilterOn = True
        Me.Refresh
        Do While Me!FullName < glvarTemp
            DoCmd.GoToRecord , , acNext
        Loop
    Else
        glvarTemp = Me!FullName
        Me.FilterOn = False
        Me.Refresh
        Do While Me!FullName < glvarTemp
            DoCmd.GoToRecord , , acNext
        Loop
    End If    
End Sub

Open in new window

0
wilbur88
Asked:
wilbur88
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:

instead of


        Do While Me!FullName < glvarTemp
            DoCmd.GoToRecord , , acNext
        Loop

use

       with me.recordsetclone
           .findfirst "[Fullname]='" & glvarTemp &"'"
           if not .nomatch then
                 me.bookmark=.bookmark
                 else
                 msgbox "Record not found"
           end if

      end with


0
 
wilbur88Author Commented:
wonderful.  thanks so much.  do you have any idea what was wrong with my approach?  It worked when you checked the checkbox, but not when you cleared it...
0
 
Rey Obrero (Capricorn1)Commented:
looks like the form lost track of the records, because the form records change
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now