Originally Posted by
ItsMe
You could give a special name to each control that is a Boolean (Toggles). Each of these Toggle Controls would have a special Tag, "IncludeInString". A For Each Statemnt would evaluated the value of each control with the IncludeInString Tag. If the value was = to -1 then the .Name would be added to the string.
Untested...
Okay, I tried that and I think that brings me one step closer. So I made the following changes to the Click events.
Code:
Private Sub tglOwner_Click()If [tglOwner].Value = -1 Then ' If Owner Selected (pressed)
Me.tglOwner.Tag = "IncludeInString"
strOwner = True
Else
strOwner = False
Me.tglOwner.Tag = ""
End If
End Sub
And then, added the loop that you suggested...
Code:
Dim ctl As Control
For Each ctl In Me.Controls
If InStr(ctl.Tag, "IncludeInString") <> 0 Then
strWHERE = strWHERE & "(Customers.[Country]= '" & ctl.Name & "') AND "
End If
Next ctl
And that works fine, but only one problem - my search string strWHERE comes out as shown below.(For the example, I selected the buttons Owner & Germany)
Code:
(Customers.[Country]= 'tglOwner') AND (Customers.[Country]= 'tglGermany')
Here is where I thought an array might help. If I can setup an array that establish the relationship between the toggle button name and the field name, problem solved.
So for the example, I might need an array like
Code:
Array myArray [0] [tglOwner, 'ContactTitle', 'Owner']
Array myArray [1] [tglSalesRep, 'ContactTitle', 'Sales Representative']
Array myArray [2] [tglGermany, 'Country', 'Germany']... and so on.
So when I find tglOwner in the loop, I can insert "Owner" to the search string so that strWHERE will come out as
Code:
(Customers.[ContactTitle]= 'Owner') AND (Customers.[Country]= 'Germany')
I am not quite sure how to define such an Array and the loop to pick up the right values from the Array. But hope this clarifies your earlier doubt about my Array reference!