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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a multiple column listbox or combobox

Status
Not open for further replies.

Davidmc555

Programmer
Feb 7, 2005
39
GB
I feel so stupid for asking this, but I've looked all over Tek-tips and google and not found what I'm looking for.

In short, I want to populate a listbox with multiple columns based on an SQL Query. The query returns 3 different elements of information, an Item ID (Not the unique ID however), it's description and it's quantity. The number of row is undetermined as the number of items could be anything, so therefore the listbox is designed to vertically scroll.

I've devised the SQL query but I'm not sure how to populate the listbox. (I know how to do it in VB.NET and now I'm working with VBA) I looked on the VB Help and MSDN but with no success. So far I got it to populate the listbox with the Item Id only.

Could anyone drop some hints as to how to show all columns and all rows?

Many thanks in advance.
 
I eventually found the solution myself and really I'm kicking myself for not coming across it sooner.

Your SQL Query will find the fields necessary and then are put into a recordset.

Then in the code I put

Code:
lbScanList.RowSourceType = "Table/Query"
lbScanList.RowSource = strSQLPackage

where lbScanList is the name of my listbox. However, that only return one column. I found in the properties of the listbox an entry called 'Column Count' which I set to 3 and it now displays every table entry on a separate line. I'm almost sure the same property can be set in code for those who don't know how many columns they will be working with.

I hope this info will be useful to someone who encounters the same problem.
 
Take a look at the ColumnCount and ColumnWidths properties of the access ListBox object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top