Results 1 to 3 of 3
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Inconsistent Code Execution


    I have a command button that runs the following code

    Code:
     If Me.FilterOn = False Then
    Me.FilterOn = True
    Me.Filter = "[Select] = -1"
    Me.Refresh
    Me.Requery
    Me.cmdFilter.Caption = "Show All"
     
    Else
    Me.FilterOn = False
    Me.Filter = ""
    Me.cmdFilter.Caption = "Show Selected"
    Me.Refresh
    End If
    This works most of the time, except when the form first opens. I've watched the code step through the True portion of the code, but my form does not respond except for the caption change, which is then out of sync with the screen since all records are being display. I've check and the FilterOn property is still false. Clicking the button again executes the same True portion of code since FilterOn is still false. This time the code executes normally, the filter applies and everything is back in sync.

    Why doesn't the code execute correctly the first time?

  2. #2
    pdebaets is offline Competent Performer
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Los Angeles
    Posts
    235
    Try this:

    Code:
    If Me.FilterOn = False Then
        Me.Filter = "[Select] = -1" 
        Me.FilterOn = True   
        Me.cmdFilter.Caption = "Show All"
    Else
        Me.FilterOn = False
        Me.cmdFilter.Caption = "Show Selected"
    End If

  3. #3
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    So simple, thanks. I'm turning the filter on before I set the filter. That explains why it works the 2nd time, but not the first.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Inconsistent??
    By bginhb in forum Programming
    Replies: 3
    Last Post: 09-07-2011, 03:10 PM
  2. VBA + SQL statement creation/execution.
    By Playerpawn in forum Access
    Replies: 3
    Last Post: 05-26-2011, 08:25 AM
  3. Replies: 5
    Last Post: 07-13-2010, 11:48 AM
  4. Pausing macro execution
    By lupis in forum Programming
    Replies: 3
    Last Post: 06-28-2010, 12:46 AM
  5. Inconsistent Query Error...
    By DHavokD in forum Queries
    Replies: 8
    Last Post: 06-11-2009, 09:58 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums