budekatude
budekatude

Reputation: 443

Create a ComboBox object to pass it into a Sub

I am trying to access a ComboBox on a UserForm from a sub. Therefore I'm trying to pass a Combobox object into it.

However, I don't seem to be able to create a Combobox Object in order to pass it in. They are always empty when entering the sub. This is what I've been trying:

Dim ctl As ComboBox

Set ctl = Me.cb_FcnName 'cb_FcnName is the name of the Combobox I'm trying to access

Call ColumnEntries2Combobox(ctl)

And this is my Sub:

Private Sub ColumnEntries2Combobox(ByRef Combo As ComboBox)
     Combo.AddItem = Worksheets(WorksheetName).Cells(currRow, 2)
End Sub

For some reason I can't seem to find any documentation on how to create the necessary combobox object to pass into the sub...

Thanks in advance for any kind of help!

Upvotes: 0

Views: 1118

Answers (1)

Andy G
Andy G

Reputation: 19367

AddItem is a method, not a property. For a method we supply arguments after a space, compared to setting a property equal to something.

So change

     Combo.AddItem = Worksheets(WorksheetName).Cells(currRow, 2)

to

     Combo.AddItem Worksheets(WorksheetName).Cells(currRow, 2)

This is a common error, so a simple demonstration is:

object.Property = value

object.Method arg1, arg2

Upvotes: 2

Related Questions