Get text from combobox

A

a.t.brooks

I have a combobox on a form. The values of the combobox are determined
by a lookup wizard which looks at a table in by DB.

I want to use refer to the text in the combobox as a string, but when
I use

Dim CB As String
CB = Me.ComboboxName

I get CB as being the value (1-5) as opposed to the text.

I have tried
Dim CB As String
CB = Me.ComboboxName.Text

Yet I get the error

"You can't reference a property or method for a control unless the
control has focus".

I've also tried
Dim CB As String
CB = Me.ComboboxName.Value

But get the number again.

Why is this not working?

Thanks in advance
Tony
 
A

Al Campagna

AT,
It should be YourComboBoxName.Name (use your own real combo name)
As in...
= "This ComboBox is Named " & YourComboBoxName.Name

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
A

a.t.brooks

Hi Al
I think you've mis-understood me. If I use ComboBoxName.Name I get the
combobox name (funnily enough) not what has been selected in the
combobox.
I know the combox box name as I set it in its properties to be
cMethod.
So cMethod.Name would be cMethod - confirmed by a tempory MsgBox(CB)
I would like whoever uses the form to be able to select a "Method" in
the combobox and then for me to have that available as a string after
an OK button has been pressed.
Thanks
 
A

a.t.brooks

Hi all
I finally figured it out.
I used the following code:


Dim CB As String
Me.ComboxName.SetFocus
CB = Me.ComboboxName.Text



Thanks anyway.
 
J

John Spencer

I would guess that the combobox is a multi-column combobox with the first
column hidden and the first column is the bound column.

You might try the following and see what you get.

Dim CB As String
CB = Me.ComboboxName.Column(1)

Columns are zero-based numbered, so the first column is column 0 and the 2nd
column is 1.

If you used
CB = Me.ComboboxName.Column(0)
you should get 1 to 5

By the way, with the above there should be no need to set the focus to the
combobox.


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
D

Douglas J. Steele

John Spencer said:
By the way, with the above there should be no need to set the focus to the
combobox.

<picky>
There's no need to set focus to the combo box unless you refer to its Text
property.
</picky>
 
J

John Spencer

<picky> <picky> <picky> <picky> <picky> <picky> <picky>
;>)

I guess I was unclear.


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top