Reputation: 3
This code resides in my the event code of my Access form. I'm trying to replace the name of the ComboBox in the 3rd line of the code below with a variable. The code works when I use the name of the ComboBox, but gives me "method or data member not found" error when I try to use a variable. I have several ComboBoxes and like to run the third line below in a loop for all of the ComboBoxes.
I think the question boils down to how do I set the variable "ComboBoxName" equal to the object cboComboBox and not the value that is currently in cboComboBox (which is currently ""). This is the code that is not working:
Dim ComboBoxName As ComboBox
Set ComboBoxName = Me.cboComboBox
Me.ComboBoxName.RowSource = ""
Upvotes: 0
Views: 5713
Reputation: 55841
How do I set the variable "ComboBoxName" equal to the object cboComboBox
It would either be:
Dim ComboBoxName As ComboBox
Set ComboBoxName = Me!cboComboBox
ComboBoxName.RowSource = ""
or:
Dim ComboBoxName As String
ComboBoxName = Me!cboComboBox.Name
Me(ComboBoxName).RowSource = ""
Upvotes: 1