Text Box Controls Linked to Combo Box

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

I am trying to create a display text box that will show a
field from a query based on a combo box on the same
form. The query cannot be made the record source of the
form because the form is being used for data entry into a
table so I am using the table as the record source for
the form. Is there a way to show the query information
based on the combo box selection on the same form?

Thanks in advance.
 
If I understand you correctly, you can use the Afterupdate Event of your
combo to "push" information into the text box. For example, let's say you
have a form that displays people's names, and you want to display their
nickname when their proper name is selected from a combo. Set the
ColumnCount of your combobox to 4, and the ColumnWidths to 0;1;1;0. Set your
Rowsource to this:

SELECT lngPeopleID, strFirstName, strLastName, strNickName FROM tblPeople

As you can see, your combo will pull all records from tblPeople, and you
combo will display the strFirstName and strLastName fields (since the first
and last column widths are set to 0). In the afterupdate event of your
combo, "push" the Nickname into a textbox:

Me.ctlNickname = Me.cboNames.Column(3)

Note that column indexes are 0 based, so the 4th column is actually #3.

If this isn't what you want, you may need to use a DLookup to lookup a value
based on the combo selection, but that's another posting.
 
Robert said:
I am trying to create a display text box that will show a
field from a query based on a combo box on the same
form. The query cannot be made the record source of the
form because the form is being used for data entry into a
table so I am using the table as the record source for
the form. Is there a way to show the query information
based on the combo box selection on the same form?

You might be able to use DLookup to retrieve the value:

DLookup("thefield", "thetable", "otherfield = " & combobox)

How/wher you would use that depends on what else you're
doing, but most likely it would be in the combo box's
AfterUpdate event procedure and maybe in the form's Current
event as well.
 
Back
Top