Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    When I looked at your sample DB I did not see anything that is outside of a basic search form. What is it that you are trying to accomplish, other than filtering data?

  2. #17
    RPACDN is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    May 2015
    Posts
    16
    Yes, it is a basic filtering. But as I mentioned, I am looping through 40 plus toggle buttons using the loop that you have suggested and that is also working fine. As you can see in the example, all I am trying to accomplish is to filter the data and then display exactly as I have demonstrated in the example. The real problem is on how to efficiently handle the 40 plus toggle buttons.

    The only piece missing is that once we determine that a button is "selected" by the User based on it's tag, how do we then determine/associate the two characteristics for each button, that is the associated "field name" and the associated "search string"?

    Example:
    - if tglGermany is selected, the associated fieldname in the table will be "Country" and the associated search string for the sql search will be "Germany".
    - if tglSalesRep is selected, the associated fieldname in the table will be "ContactTitle" and the associated search string for the sql search will be "Sales Representative".

    Hope this helps.

    Apologize for the confusion, but I think the example gives you a better understanding of exactly what I am trying to do. I already have the code that you suggested in there, so now it is just a matter of modifying it to determine the "field name" and the "search string" for each button pressed.

  3. #18
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Review post 10 and 12 then
    Start here...
    if tglGermany is selected, the associated fieldname in the table will be "Country" and the associated search string for the sql search will be "Germany".
    Do not name any control tglGermany. Instead, name it Germany. Pass the name of the control to your strWHERE, as criteria.

    Pass the name of the control to the criteria, only, if the control's value is -1
    Code:
                    If ctl.value = -1 then
                         strWHERE = strWHERE & "(Customers.[Country]= '" & ctl.Name & "') AND "
                    End if

  4. #19
    RPACDN is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    May 2015
    Posts
    16
    Yes, I suppose I can take that approach to pass the "search string" to strWHERE, but still the "field name" (such as Country, ContactTitle etc) remains to be updated depending on the selected button!

    Code:
     If ctl.value = -1 then 
                strWHERE = strWHERE & "(Customers.[Country]= '" & ctl.Name & "') AND "
             End if

  5. #20
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    but still the "field name" (such as Country, ContactTitle etc) remains to be updated depending on the selected button
    There is not any need to update field names or make any edits to tables. Use different tags for the controls associated to different field names.

  6. #21
    RPACDN is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    May 2015
    Posts
    16
    Okay, I made some changes to my approach and I think I have a way forward on this now. For anyone who is interested in the solution, see the code changes below that I made to the sample database.

    The only drawback or limitation is that you can not use the tag control of your toggle buttons for anything else in the design. In some cases, designers use that for displaying hints to the User etc., but that won't be possible, because this script solely depends on the value in the tag field. Again, another reason why I would've preferred to use an array.

    I changed the on event click for each button as follows:

    Code:
    Private Sub tglOwner_Click()
    If [tglOwner].Value = -1 Then  ' If Owner Selected (pressed)
        Me.tglOwner.Tag = "include_ContactTitle"
    Else
        Me.tglOwner.Tag = ""
    End If
    End Sub
    Private Sub tglGermany_Click()
    If [tglGermany].Value = -1 Then  ' If Owner Selected (pressed)
        Me.tglGermany.Tag = "include_Country"
    Else
        Me.tglGermany.Tag = ""
    End If
    End Sub
    Then updated the search on click event as follows:
    Code:
    Private Sub tglSearch_Click()    'Purpose:   Build up the criteria string form the non-blank search boxes, and apply to the form's Filter.
        Dim lngLen As Long                      'Length of the criteria string to append to.
        Dim strFieldName As String                    
        Dim strSearchString As String
    
        Dim ctl As Control
            For Each ctl In Me.Controls
                If InStr(ctl.Tag, "include_") <> 0 Then
                strFieldName = Right(ctl.Tag, Len(ctl.Tag) - 8)  ' strip out include_ from the string
                strSearchString = Right(ctl.Name, Len(ctl.Name) - 3) ' strip out tgl from the string
                    strWHERE = strWHERE & "(Customers.[" & strFieldName & "]= '" & strSearchString & "') AND "
                End If
            Next ctl
    
        lngLen = Len(strWHERE) - 5
        If lngLen <= 0 Then     
            MsgBox "No Filter Criteria Provided", vbInformation, "Nothing to do."
        Else                   
            strWHERE = Left$(strWHERE, lngLen)
    
            'Finally, apply the string as the form's Filter.
            Me.Filter = strWHERE
            Me.FilterOn = True
        End If
        strWHERE = ""
    End Sub
    Thanks to "ItsMe" for the time and patience to work with me on this solution.

    If I come up with a different solution, I will post it here. I can upload the updated database, if anybody is interested.

    Thank you to everyone who replied. I know I wasn't very good in explaining my problem originally!

  7. #22
    RPACDN is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    May 2015
    Posts
    16
    If anyone is interested in seeing how arrays can be used to cycle through the toggle buttons, take a look at my other post
    https://www.accessforums.net/program...tml#post278354

    Just one of many ways to process multiple buttons.

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

Similar Threads

  1. Filtering Subform with Toggle Buttons
    By doubleohkevin in forum Forms
    Replies: 3
    Last Post: 09-30-2014, 02:13 PM
  2. Shape Effect on Toggle Buttons
    By dimoc in forum Access
    Replies: 5
    Last Post: 04-10-2014, 09:28 AM
  3. Text String from Form Query - Multiple Choices
    By wrandyrice in forum Access
    Replies: 1
    Last Post: 08-12-2012, 10:58 AM
  4. Replies: 1
    Last Post: 06-16-2012, 02:50 PM
  5. create table using something like loop query
    By learning_graccess in forum Queries
    Replies: 20
    Last Post: 04-18-2012, 09:52 AM

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