Form Combo Box

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

Guest

I have a form with a combo box lookup. Besides bring back the lookup field,
how can I bring back a 2nd field from the lookup table to the record in the
form
 
Define the combo box control as having 2 or more columns. Include the extra
columns in the query feeding the combo box. Use the .column syntax to refer
to the extra column(s) (look in Access help for details)

-Dorian
 
Thank you but I have not found the column systax that works. I have not been
able to fill in the 2nd field.It has the same name as the query in the combo
 
Copied directly from Access HELP:

Column Property
See AlsoApplies ToExampleSpecificsYou can use the Column property to refer
to a specific column, or column and row combination, in a multiple-column
combo box or list box. Read-only Variant.

expression.Column(Index, Row)
expression Required. An expression that returns one of the objects in the
Applies To list.

Index Required Long. A long integer that can range from 0 to the setting
of the ColumnCount property minus one.

Row Optional Variant. An integer that can range from 0 to the setting of
the ListCount property minus 1.

This property setting is only available by using a macro or Visual Basic.
This property setting isn't available in Design view and is read-only in
other views.

Remarks
Use 0 to refer to the first column, 1 to refer to the second column, and so
on. Use 0 to refer to the first row, 1 to refer to the second row, and so on.
For example, in a list box containing a column of customer IDs and a column
of customer names, you could refer to the customer name in the second column
and fifth row as:

Forms!Contacts!Customers.Column(1, 4)

You can use the Column property to assign the contents of a combo box or
list box to another control, such as a text box. For example, to set the
ControlSource property of a text box to the value in the second column of a
list box, you could use the following expression:

=Forms!Customers!CompanyName.Column(1)

If the user has made no selection when you refer to a column in a combo box
or list box, the Column property setting will be Null. You can use the IsNull
function to determine if a selection has been made, as in the following
example:

If IsNull(Forms!Customers!Country)
Then MsgBox "No selection."
End If

Note To determine how many columns a combo box or list box has, you can
inspect the ColumnCount property setting.

Example
The following example uses the Column property and the ColumnCount property
to print the values of a list box selection.

Public Sub Read_ListBox()

Dim intNumColumns As Integer
Dim intI As Integer
Dim frmCust As Form

Set frmCust = Forms!frmCustomers
If frmCust!lstCustomerNames.ItemsSelected.Count > 0 Then

' Any selection?
intNumColumns = frmCust!lstCustomerNames.ColumnCount
Debug.Print "The list box contains "; intNumColumns; _
IIf(intNumColumns = 1, " column", " columns"); _
" of data."

Debug.Print "The current selection contains:"
For intI = 0 To intNumColumns - 1
' Print column data.
Debug.Print frmCust!lstCustomerNames.Column(intI)
Next intI
Else
Debug.Print "You haven't selected an entry in the " _
& "list box."
End If

Set frmCust = Nothing

End Sub
 
Back
Top