Getting column data from selected item in combo box

  • Thread starter Thread starter Tim Rogers
  • Start date Start date
T

Tim Rogers

I believe this is real simple, but for some reason I'm having
difficulty with it. I have a combo box and I want to get the value of
the bound column (0) in the combo box for the selected item. I tried
to do the following:

Dim iTopicId As Object
Set iTopicId = cmbTopIssues.Column(0)

I tried to make iTopicId an Integer and a Variant as well, but neither
worked. Although, I could do:

MsgBox cmbTopIssues.Column(0)

and the value would display just fine. So, I thought that Column()
returned a Variant. I believe my problem here is just a basic lack of
knowledge of VBA I suppose. Any help would be appreciated.

Thanks,

Tim Rogers
 
If all you really want is the value of the combo box, you
should be able to assign it to a variable as:

iTopicId = cmbTopIssues

Where iTopicID is a non-object variable of an appropriate
data type. I don't think that you need to specify column
0, it will default.

If you want iTopicID to be an object variable that will
represent cmbTopIssues (with all of the properties,
column values etc) then you would use:

Set iTopicId = cmbTopIssues

The problem with your earlier code was that it was trying
to assing a single value to an object variable. If you
use the object variable, you need to set it equal to the
entire object, not just one of it's values. The problem
you were having with trying to assign that value to a
regular variable was that you were using the Set
statement. The Set statement is only used in assigning
object variables. Regular variable are assigned with the
optional Let statement, which is usually omitted.

Hope this helps.
 
Back
Top