Hi everyone,
I found a good piece of VBA code on this site to group multiple form textBox and comboBox fields together using the TAG property and then apply the enabled or disabled property to them, based on a selected value from a comboBox. The function is:
The form action is:
The above works perfectly for single tags (for example, if 7 is selected in the comboBox, then only fields with the TAG "7" are enabled, and the same for "8" and so on), but........what I'd like to do is display all the fields with 7 and 8 TAGS based on the combo box selection. So...you select 8 in the comboBox and all fields with TAGs 7 and 8 are enabled.
I have tried r = ShowHideControls(Me, "7" And "8") and this doesn't work. I have tried other variations of this, but the code only allows for one TAG to be specified and passed to the form.
Any help would be greatly appriciated.
I found a good piece of VBA code on this site to group multiple form textBox and comboBox fields together using the TAG property and then apply the enabled or disabled property to them, based on a selected value from a comboBox. The function is:
Code:
Function ShowHideControls(frm As Form, strTAGtoUse As String)
Dim ctl As Control
For Each ctl In frm.Controls
intControlType = ctl.ControlType
If (intControlType = acComboBox) Or (intControlType = acTextBox) Then
ctl.Enabled = (InStr(1, ctl.Tag, strTAGtoUse) > 0)
End If
Next ctl
End Function
The form action is:
Code:
Private Sub Form_Current()
ElseIf Me.Parent.Parent.[No: Stations] = "7" Then
r = ShowHideControls(Me, "7")
ElseIf Me.Parent.Parent.[No: Stations] = "8" Then
r = ShowHideControls(Me, "8")
End If
End Sub
The above works perfectly for single tags (for example, if 7 is selected in the comboBox, then only fields with the TAG "7" are enabled, and the same for "8" and so on), but........what I'd like to do is display all the fields with 7 and 8 TAGS based on the combo box selection. So...you select 8 in the comboBox and all fields with TAGs 7 and 8 are enabled.
I have tried r = ShowHideControls(Me, "7" And "8") and this doesn't work. I have tried other variations of this, but the code only allows for one TAG to be specified and passed to the form.
Any help would be greatly appriciated.