How do I get the combo box value?

jSteve

New member
Local time
Today, 08:53
Joined
Apr 30, 2008
Messages
2
I've got a 1 column combo box on a form with values in. I would like to use the selected value in some vba that is activated on change which writes the value into the SQL to select the top x amount of records in a query. The writing to SQL bit works fine if I manually type the value into the string that gets written into the SQL but I what I really want is to have the value as a variable taken from the combo box. Anyone know what code might work?

thanks in advance,

Steve
 
well if your combo box is named cboName then:

cboName.Value should work
 
I was trying rangex = combo51.value and it was giving me all sorts of excuses for not working. Have just used combo51.value instead and it's worked, cheers.
 
What's in a name?

In working with Access, allowing Access to name objects for you is fine if you never write code. However, if writing code, I find it best to rename the objects to show what data is being stored there. The name combo51 is not very descriptive and you may find yourself confused if doing complex coding. The typical naming convention for a combobox is cboName (with Name being replaced by the descriptive term defining the data to be stored). Just a suggestion.
 
Yup - get into that habbit.

Text boxes are txtInfo, txtID, etc.

I always preface my objects with identifiers. qry, tbl, frm, rpt, subfrm, subrpt, etc.

txt, cbo, lbl, memo, lst, cmd, tgl, etc.

This way most people looking at code or things - if they don't know exactly what I'm referring to, at least they can see something like frmMain or txtID and then at least they will know I'm referring to a form or text box. Then from the name you can guess at where it is, etc.
 

Users who are viewing this thread

Back
Top Bottom