Change text box as combo changes

  • Thread starter Thread starter Phil
  • Start date Start date
P

Phil

Hi,

This is a simple example of that I would like to do:

Name table:
Code name

1 Joe
1 Mary
3 Judy
2 Mike

Status table:
Code Status

1 Married
2 Single
3 unknown

I have a form with a combox box and a text box. The combo
box pulls from the Name table. When I select a person
from the name combo box I want the text box to show their
status. For Example: If I select Mary in the combo box
the text box would show Married.

I would think this is simple and when someone tells me how
to do it I will probably feel dumb.

Thanks,
Phil
 
Easiest way would probably be to join the two tables together, so that you
show both the name and the status in the query. The SQL would look something
like:

SELECT [Name].Code, [Name].[Name], [Status].[Status]
FROM [Name]
INNER JOIN [Status]
ON [Status].
Code:
 = [Name].[Code]
ORDER BY [Name].[Name]

Change the property for your combo box so that it has 3 fields. Set the
widths to 0;1;0 (you can make the width of the middle one wider if you want,
and you can show the status too if you want).

In the combo's AfterUpdate event, put code like

Me.txtStatus = Me.cboName.Columns(2)

What this does is put the value of the 3rd column (they start numbering at
0) into the textbox.

(Replace txtStatus and cboName with the name of your textbox and combobox
respectively.)

BTW, Name, Status and Code are NOT good names to use for tables and fields.
They're reserved words, and their use can lead to problems.
 
Back
Top