Hi all. Thanks in advance for any help you can give me; this is rather vexing. I have 4 combo boxes (lvl0_ComboBox,... lvl3_ComboBox) in a sheet titled "Data Input". Because I end up needing to reset them to default a lot I made the following function:
I'm having trouble passing the objects in an elegant way. The subroutine where I call resetCombo() from is in a module, so I have to get specific. If my module reads:
then everything works fine. But I want to save myself from some errors (especially since the page name is subject to change), so I tried to simplify:
but this gives me a "Method or data member not found" error, highlighting the line in the whatever() sub. I did some searching online and thought that maybe it would work if I passed it as an OLEObject:
When I run the clear outside of the function (3rd to last line) I don't get any errors, but when I try to pass it to resetCombo() (2nd to last line) I get the "Object doesn't support this property or method" error.
I've got everything working now using Worksheets("Data Input").X, but I'd really like the more concise way. Does anyone see what I'm doing wrong? Thanks again.
Code:
Function resetCombo(cmboBox As Object)
' Resets combo to only have value "[any]"
With cmboBox
.Clear
.AddItem "[any]"
.Value = "[any]"
End With
End Function
I'm having trouble passing the objects in an elegant way. The subroutine where I call resetCombo() from is in a module, so I have to get specific. If my module reads:
Code:
Call resetCombo(resetCombo(Worksheets("Data Input").lvl1_ComboBox)
then everything works fine. But I want to save myself from some errors (especially since the page name is subject to change), so I tried to simplify:
Code:
Public InputSheet As Worksheet
Sub whatever()
Set InputSheet = Worksheets("Data Input")
Call resetCombo(InputSheet.lvl1_ComboBox)
End Sub
but this gives me a "Method or data member not found" error, highlighting the line in the whatever() sub. I did some searching online and thought that maybe it would work if I passed it as an OLEObject:
Code:
Public InputSheet As Worksheet
Sub whatever()
Dim cmboBoxes as Object
Set InputSheet = Worksheets("Data Input")
Set cmboBoxes = InputSheet.OLEObjects
cmboBoxes("lvl1_ComboBox").clear
Call resetCombo(cmboBoxes("lvl1_ComboBox")
End Sub
When I run the clear outside of the function (3rd to last line) I don't get any errors, but when I try to pass it to resetCombo() (2nd to last line) I get the "Object doesn't support this property or method" error.
I've got everything working now using Worksheets("Data Input").X, but I'd really like the more concise way. Does anyone see what I'm doing wrong? Thanks again.