First make sure that these related fields are included in the
rowsource of the combo and make sure that you increase the Column
Count property to include any new fields. Adjust the ColumnWidths
property according to whether you want to see the values when the
combo is dropped down. Then for each related field you want to
display create a textbox. In the ControlSource of the new textbox put
=me.MyCombo.column(3)
Then because the column property is indexed starting with 0, replace
3 with the column number minus 1 of the field you want to display.
IOW, the above will cause the value from the 4th column to be
displayed in the textbox.
Note that this is not the same thing as navigating to the record
with the matching company id. That is also pretty simple to do:
Here's what you need to accomplish the record navigation (make the
record with the key matching the selected value the current record).
Create your unbound listbox. Make sure the bound column of the
list/combo is the primary key field for your table. In the
AfterUpdate event of the listbox you would have the following code:
with me.recordsetclone
.findfirst "PrimaryKey=" & me.lstPrimaryKey
if not .nomatch then
me.bookmark=.bookmark
endif
end with
Replace "PrimaryKey" with the name of the primary key field in the
forms Recordsource and replace "lstPrimaryKey" with the name of the
listbox control.
If the Primary key field is text you will need to revise the
findfirst line to wrap the value coming from the unbound listbox in
quotes. This is easily done by putting a pair of quote characters
everywhere a quote character should appear. Note that there are 3
quotes (") before the first & and 4 quotes after the second &
..findfirst "PrimaryKey=""" & me.lstPrimaryKey & """"
--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.
I have one table in the database, having company ID, name and
address.. In a form I wish to use a combo-box (or something similar)
to select a specific company and a text box should give the
corresponding address. At this stage I do not wish to change any of
that data. How do I link the address-text-box to the choice made by
the combo.box?
I'm sure it's simple, but I just have no clue.
Johannes