Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Boxes - populate from table 1

Status
Not open for further replies.

NKA

Programmer
Mar 20, 2002
76
NZ
I have a combo box which looks up values from a table. This combo box has 2 columns, the first being the bound column (and is based on autonumber).

When opening the form, I would like the combo box to display the text "Select" or "Choose" - without having to add it to the table as an entry.

Is there an easy way of doing this? I am not familiar with how to populate a combo box using modules - but I think this is where I would be able to do it... I just need some guidance!

Much appreciated if anyone can help. NKA

The answer's always easy - if you know it! ;-)
 
One way is to create a query to union with the current combobox rowsource that returns only one record.

For example:

Select 0, 'Choose'
Union
Select [Column1], [Column2] from [YourTable]

Happy colding! Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
Thank you for your advise - but I think I am being extremely thick! Where do I put this? In one of the events for the combo box itself or the form onOpen event?

Also, when I try to do this I think I am missing something as the 1st and 3rd line are highlighted in red with a compile error: syntax error message.

(I did say I wasn't sure how to do this!!)

Can you give me a little more help please? NKA

The answer's always easy - if you know it! ;-)
 
The union sql string goes in the RowSource property of the combobox:

For example:

Select 0, 'Choose' from [Your Table] Union Select [Column1], [Column2] from [YourTable];

I think I left out the from claues in the original post.
[blush]

Let me know! Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
You rock! It works a dream. I will find this extremely useful for many forms now!!

I don't suppose you know how to generate/populate combo boxes using VBA do you? I always use the wizard but would like to know how to do it using code! I get all confused with dims and things! NKA

The answer's always easy - if you know it! ;-)
 
Once you set the combobox up with the wizard to get the number of columns, column widths, etc. you can set the RowSource using code similar to this:

Me![ComboBox1].RowSource = "Select [Field1],[Field2] FROM [YourTable] ORDER BY [Field1] ;"

You can also set column widths, the bound column, etc. programmatically, check the Access Help for more info.

Have fun! Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top