Results 1 to 5 of 5
  1. #1
    jasdem is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    27

    Combining multiple toggle button filters

    I have a form that I use to filter a sub-form. In the form I have 4 toggle buttons that filter the corresponding fields in the sub-form quite well. What I would like to have is when one toggle is selected, the user can select a second or third toggle to further refine their inquiry. I am attaching the code that I used for the individual filters.

    Code:
    
    Private Sub Toggle_Filter_DOB_Click()
    
    
    If Me.Toggle_Filter_DOB = True Then
         [Forms]![Phase 2]![FormPhase2_sub].Form.Filter = "DOB = #" & Me.ATS_DOB & "#"
         [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = True
         
         Me.Toggle_Filter_DOB.Caption = "Filter On"
         
    Else
         [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = False
         Me.Toggle_Filter_DOB.Caption = "Filter Off"
    End If
    
    
    End Sub
    
    
    Private Sub Toggle_Filter_FN_Click()
    
    
    If Me.Toggle_Filter_FN = True Then
         [Forms]![Phase 2]![FormPhase2_sub].Form.Filter = "FirstName = '" & Right([Student_First_Name], (Len([Student_First_Name]) - 1)) & "'"
         [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = True
         Me.Toggle_Filter_FN.Caption = "Filter On"
    Else
         [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = False
         Me.Toggle_Filter_FN.Caption = "Filter Off"
    End If
    
    
    End Sub
    
    
    Private Sub Toggle_Filter_GLN_Click()
    
    
    If Me.Toggle_Filter_GLN = True Then
         [Forms]![Phase 2]![FormPhase2_sub].Form.Filter = "LastName = '" & Me.Guardian_Last_Name & "'"
         [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = True
         Me.Toggle_Filter_GLN.Caption = "Filter On"
    Else
         [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = False
         Me.Toggle_Filter_GLN.Caption = "Filter Off"
         
    End If
    
    
    End Sub
    
    
    Private Sub Toggle_Filter_LN_Click()
    
    
    If Me.Toggle_Filter_LN = True Then
         [Forms]![Phase 2]![FormPhase2_sub].Form.Filter = "LastName = '" & Me.Student_Last_Name & "'"
         [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = True
         Me.Toggle_Filter_LN.Caption = "Filter On"
    Else
         [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = False
         Me.Toggle_Filter_LN.Caption = "Filter Off"
    End If
    
    
    End Sub

    Any help would be appreciated.
    Last edited by jasdem; 09-17-2013 at 11:42 AM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    You can build the filter string based on conditional code. Review: http://allenbrowne.com/ser-62code.html

    Something like:

    Dim strWHERE As String
    'code to build the string
    ...
    [Forms]![Phase 2]![FormPhase2_sub].Form.Filter = strWHERE
    [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = True
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jasdem is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    27
    Thanks for the lead. I put together the new code but seem to have some syntax errors.

    [code]

    Private Sub Toggle_Filter_DOB_Click()


    Dim strWhere As String
    Dim lngLen As Long


    If Me.Toggle_Filter_DOB = True Then
    strWhere = strWhere & "DOB = #" & Me.ATS_DOB & "#" And ""
    End If


    If Me.Toggle_Filter_FN = True Then
    strWhere = strWhere & "FirstName = '" & Right([Student_First_Name], (Len([Student_First_Name]) - 1)) & "'" And ""
    End If


    If Me.Toggle_Filter_LN = True Then
    strWhere = strWhere & "LastName = '" & Me.Student_Last_Name & "'" And ""


    If Me.Toggle_Filter_GLN = True Then
    strWhere = strWhere & "LastName = '" & Me.Guardian_Last_Name & "'" And ""
    End If


    lngLen = Len(strWhere) - 5


    [Forms]![Phase 2]![FormPhase2_sub].Form.Filter = strWhere
    [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = True




    End Sub

    [\code]

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Check Allen's code again. Need to trim 5 characters from the end of strWhere. You are missing the If Then structure after line to set the lnglen variable.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    jasdem is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    27
    Thanks for all the help. I was able to produce a code that works

    [code]

    Private Sub Toggle_Filter_LN_Click()


    Dim strWhere As String
    Dim lngLen As Long
    'Const conJetDate = "\#mm\/dd\/yyyy\#"


    If Me.Toggle_Filter_DOB = True Then
    strWhere = strWhere & "(DOB = #" & Me!ATS_DOB & "#) And "
    Me.Toggle_Filter_DOB.Caption = "Filter On"
    Else
    Me.Toggle_Filter_DOB.Caption = "Filter Off"
    End If


    If Me.Toggle_Filter_FN = True Then
    strWhere = strWhere & "(FirstName = '" & Right(Me!Student_First_Name, Len(Me!Student_First_Name) - 1) & "') And "
    Me.Toggle_Filter_FN.Caption = "Filter On"
    Else
    Me.Toggle_Filter_FN.Caption = "Filter Off"
    End If


    If Me.Toggle_Filter_LN = True Then
    strWhere = strWhere & "(LastName = '" & Me!Student_Last_Name & "') And "
    Me.Toggle_Filter_LN.Caption = "Filter On"
    Else
    Me.Toggle_Filter_LN.Caption = "Filter Off"
    End If


    If Me.Toggle_Filter_GLN = True Then
    strWhere = strWhere & "(LastName = '" & Me!Guardian_Last_Name & "') And "
    Me.Toggle_Filter_GLN.Caption = "Filter On"
    Else
    Me.Toggle_Filter_GLN.Caption = "Filter Off"
    End If


    lngLen = Len(strWhere) - 5


    If lngLen <= 0 Then
    Else
    strWhere = Left$(strWhere, lngLen)



    [Forms]![Phase 2]![FormPhase2_sub].Form.Filter = strWhere
    [Forms]![Phase 2]![FormPhase2_sub].Form.FilterOn = True


    End If
    End Sub

    [\code]

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

Similar Threads

  1. Replies: 14
    Last Post: 07-22-2013, 12:39 PM
  2. Use Toggle button to select subform value
    By DerekAwesome in forum Forms
    Replies: 7
    Last Post: 12-02-2012, 07:15 PM
  3. Toggle Button Help
    By dbalilti in forum Access
    Replies: 1
    Last Post: 07-05-2012, 04:23 AM
  4. Toggle Button Criteria
    By tylerg11 in forum Forms
    Replies: 2
    Last Post: 03-02-2012, 09:28 AM
  5. Toggle Button Options
    By Matthieu in forum Forms
    Replies: 2
    Last Post: 11-23-2009, 04:05 PM

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