Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142

    See my post #14

  2. #17
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi

    That only displays whichever Toggle I click
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  3. #18
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    That's strange, it works just as you've requested on my machine. Can you post your latest full code or db?

  4. #19
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi

    I tried this:

    Code:
    Private Sub cmdFilter_Click()
    
    
    10        On Error GoTo cmdFilter_Click_Error
    
    
          Dim filter As String
              
    20        filter = ""
    
    
    30    If Me.Toggle0 Or Me.Toggle1 = -1 Then
    
    
    40    Me.filter = ("Left([Lane],3) Like '*" & Me.Toggle0.Caption & "'") And ("Left([Lane],3) Like '*" & Me.Toggle1.Caption & "'")
           
    50        Debug.Print filter
    60    End If
    70        On Error GoTo 0
    80        Exit Sub
    
    
    cmdFilter_Click_Error:
    
    
    90        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdFilter_Click, line " & Erl & "."
    
    
    End Sub
    It only filter to whichever Toggle I select.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  5. #20
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    It looks you're trying to be clever around line 30 and 40 but it's not working out.

    Try this from post #14:

    Code:
    Private Sub cmdFilter_Click()
        Dim fltr As String
        
        fltr = ""
    
        If IsNull(Me.Toggle0) Then Me.Toggle0 = False
        If IsNull(Me.Toggle1) Then Me.Toggle1 = False
        
        If Me.Toggle0 Then
            fltr = "[Lane] Like 'BNE*'"
        End If
        
        If Me.Toggle1 Then
            If fltr <> "" Then fltr = fltr & " OR "
            fltr = fltr & "[Lane] Like 'ADL*'"
        End If
        
        Debug.Print fltr
        
        If fltr <> "" Then
            Me.Filter = fltr
            Me.FilterOn = True
        Else
            Me.FilterOn = False
        End If
    End Sub

  6. #21
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi

    Cancel my last I closed the Form and Reopened and it now does exactly what I need.

    Many thanks for this
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  7. #22
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi KD2017

    So building on those 2 Toggle buttons working how would I modify the code when I have 4 Toggle Buttons like this:-

    Code:
    30        If IsNull(Me.Toggle0) Then Me.Toggle0 = False
    40        If IsNull(Me.Toggle1) Then Me.Toggle1 = False
    41        If IsNull(Me.Toggle2) Then Me.Toggle2 = False
    42        If IsNull(Me.Toggle3) Then Me.Toggle3 = False
    Toggle2 Caption is SYD
    Toggle3 Caption is MLB
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  8. #23
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    This would be the pattern

    Code:
    Private Sub cmdFilter_Click()
        Dim fltr As String
        
        fltr = ""
        
        If IsNull(Me.Toggle0) Then Me.Toggle0 = False
        If IsNull(Me.Toggle1) Then Me.Toggle1 = False
        If IsNull(Me.Toggle2) Then Me.Toggle2 = False
        If IsNull(Me.Toggle3) Then Me.Toggle3 = False
        
        If Me.Toggle0 Then
            fltr = "[Lane] Like 'BNE*'"
        End If
        
        If Me.Toggle1 Then
            If fltr <> "" Then fltr = fltr & " OR "
            fltr = fltr & "[Lane] Like 'ADL*'"
        End If
        
        If Me.Toggle2 Then
            If fltr <> "" Then fltr = fltr & " OR "
            fltr = fltr & "[Lane] Like 'SYD*'"
        End If
        
        If Me.Toggle3 Then
            If fltr <> "" Then fltr = fltr & " OR "
            fltr = fltr & "[Lane] Like 'MLB*'"
        End If
        
        Debug.Print fltr
        
        If fltr <> "" Then
            Me.Filter = fltr
            Me.FilterOn = True
        Else
            Me.FilterOn = False
        End If
    End Sub
    There might be a better way to handle the null conditions. Is the null state a result of the Triple State property? Maybe if you set the default value to all the toggle buttons as false it won't ever load as null?

  9. #24
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Quote Originally Posted by kd2017 View Post
    It looks you're trying to be clever around line 30 and 40 but it's not working out.

    Try this from post #14:

    Code:
    Private Sub cmdFilter_Click()
        Dim fltr As String
        
        fltr = ""
    
        If IsNull(Me.Toggle0) Then Me.Toggle0 = False
        If IsNull(Me.Toggle1) Then Me.Toggle1 = False
        
        If Me.Toggle0 Then
            fltr = "[Lane] Like 'BNE*'"
        End If
        
        If Me.Toggle1 Then
            If fltr <> "" Then fltr = fltr & " OR "
            fltr = fltr & "[Lane] Like 'ADL*'"
        End If
        
        Debug.Print fltr
        
        If fltr <> "" Then
            Me.Filter = fltr
            Me.FilterOn = True
        Else
            Me.FilterOn = False
        End If
    End Sub
    Yes, it does Mike, you are just fortunate that as they are boolean, it will work.

    You could just as easy have
    Code:
    30    If Me.Toggle0 Or Me.Toggle1 = Then
    and it will work.
    However it would not for most other non boolean tests, so do not get into this habit of OR'ing tests like that.

    However if your filter choices are growing in number like weeds, you might want to consider another method, like a multi select listbox and one button?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #25
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi

    That works just great.

    I can see the Login in the pattern what I get lost on is the basic syntax

    Many thanks
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Toggle Button to Add Text to a Field
    By cohnhead in forum Forms
    Replies: 11
    Last Post: 11-19-2014, 06:29 PM
  2. Replies: 3
    Last Post: 06-27-2012, 10:57 AM
  3. remove toggle filter button!?
    By Wombat in forum Access
    Replies: 1
    Last Post: 05-16-2012, 01:50 PM
  4. Toggle Filter on and off
    By Paul H in forum Forms
    Replies: 1
    Last Post: 09-14-2011, 05:54 PM
  5. Replies: 1
    Last Post: 09-13-2010, 01:57 PM

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