Combo Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm not quite sure how to show multiple fields in a combo box on a form. For
example, how to show an ID from a table and the Date & Time. Is this even
possible?

Thanks
 
Ro,

There are two parts to a combo; the textbox portion, and the list portion.
The textbox portion (the part you can enter text into) will only display one
value at a time. The list (drop-down) portion can display multiple values
both horizontally as well as vertically.

Each horizontal row represents a row in the combo's record source.

To display multiple values horizontally, you enter the name of a table or
query (or create one) in the combo's RowSource property, which returns
multiple columns (fields). You have to set the combo's ColumnCount property
equal to the number of columns returned by this table/query, plus you have
to set the display width of each of those columns in the combo's
ColumnWidths property. For example, if I were to set the combo's RowSource
as follows:

SELECT CustomerID, CompanyName, ContactName
FROM Customers

....and set ColumnCount = 3, and finally set the ColumnWidths property as
follows:

0cm;2cm;2cm

....then I would see the company name and contact names in the list portion
when I drop it down.

If I then tried to type a value into the textbox portion, I would have to
enter a company name, because it is the first visible column. This is also
the value that is tested if I set the combo's LimitToList property to True.

When the combo is not dropped-down, the value you'll see is the first column
that has a positive non-zero width (in ColumnWidths).

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
A dropdown can show 1 column when a value is selected.
However when you are in dropdown mode you can show multiple columns.

Hereby Some example

Row Source = "SELECT ID, Name FROM Table"
Column Count=2
Bound Column=1
Column Widths=0;

This will give you a dropdown using the ID as value but showing only the Name

Row Source = "SELECT ID, Name, ID as Number FROM Table"
Column Count=3
Bound Column=1
Column Widths=0;

This will also give you a dropdown using the ID as value and showing only
the Name when a value is selected. Whenever the dropdown is opened it will
show 2 columns namely Name and Number

Row Source = "SELECT ID, Name & " (" & ID &")" as ExtendedName FROM Table"
Column Count=2
Bound Column=1
Column Widths=0;

This will give you again a dropdown using the ID as value but showing the
Name concatenated with ID in brackets. Whenever a value is selected you will
see both the name and the ID

I Hope this helps you.

- Raoul
 
Back
Top