Reputation: 447
I have some comboboxes on a form and I'd like each box's RowSource
to refer to the tag I set. The tag will filter the appropriate dropdown options from a table.
SELECT DropdownNames
FROM Table
WHERE DropdownCategory=[Screen].[ActiveForm]![Me].[Tag]
What is the correct syntax? Is using the tag the best way to do this or is there a better property for this purpose?
Upvotes: 0
Views: 56
Reputation: 5386
Here's example of what I suggested.
Option Explicit
Private Sub Form_Load()
Const DROPDOWN_SQL As String = "SELECT DropdownNames FROM Table WHERE DropdownCategory = "
Const DOUBLE_QUOTES As String = """"
Dim ctl As Control
Dim strRowsource As String
For Each ctl In Me.Controls
With ctl
' Only look at Tagged Combo Boxes
If (.ControlType = acComboBox) And (.Tag <> "") Then
' Set Dropdown Row Source
strRowsource = DROPDOWN_SQL & DOUBLE_QUOTES & .Tag & DOUBLE_QUOTES
.RowSource = strRowsource
End If
End With
Next
Set ctl = Nothing
End Sub
Upvotes: 1