Solved

Microsoft Access- FilterOn affects DoCmd.GoToRecord?

Posted on 2009-04-10
3
1,163 Views
Last Modified: 2013-11-28
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
Comment
Question by:wilbur88
  • 2
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 24119175

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
 

Author Closing Comment

by:wilbur88
ID: 31569046
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24120395
looks like the form lost track of the records, because the form records change
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question