Link to home
Start Free TrialLog in
Avatar of joshinh
joshinh

asked on

How do you update Textboxes based on selected value in ComboBox??

I have an Access Form that contains a combobox (Combo0), a Textbox (Text1), and another Textbox (Text2).  There is a table that has a column of cities called NAME, a column of States called ST, and a column of Zips called ZIP.  The Combo0 is populated by all values in NAME.  Whenever I select a value in Combo0, I want Text1 and Text2 to be updated to show their values.  Thank you for your time.
Avatar of Markus Fischer
Markus Fischer
Flag of Switzerland image

Select three columns in your combo: NAME, ST, and Zips. Hide the second and third columns:

    Column Count: 3
    Column Width: ;0;0

Then use these expressions in your text boxes:

    = Combo0.Column(1)
    = Combo0.Column(2)

Cheers!
(°v°)
Avatar of joshinh
joshinh

ASKER

Harfang-

So that I understand you correctly, If I right click on the ComboBox and go to Properties - in Format I set the Column Count to 3 and the Column Widths to 0"?  In the Event field on After Update I select [Event Procedure] and select the elipsis to navigate to the VB Editor and in the After Update event for the ComboBox put  Text1 = Combo0.Column(1)
                         Text2 = Combo0.Column(2)

Something must be wrong with this because the Textboxes don't get updated with the above procedure.

Regards,
ASKER CERTIFIED SOLUTION
Avatar of Markus Fischer
Markus Fischer
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joshinh

ASKER

harfang-  It works for the most part.  When I open the form, whichever item in the combobox is selected by default, then both my textboxes have no value (even though there is really a value in the spreadsheet it is pulling it from).  If I then select any value in the combobox other than the default value, both my textboxes get populated properly.  What is causing this and how can I fix that?

Thanks for your help.
I'm concerned about "there is really a value in the spreadsheet". Are you linking from Excel? This would cause some serious delays and perhaps explain the missing information...

Is your form a bound form? If it is, the current event should get fired, the main combo should receive the information of the first record displayed and the text boxes should update. If you have an unbound form, make sure that the default value of the combo is a valid entry. One that does indeed have data in the other columns.

Perhaps you can also try to play with the "Limit to List" property? If it's not set, you might have an invalid entry as main (bound) column, and Null results for the other columns.

(°v°)
Hi harfang-

I'm trying to determine whether my form is bound or not.  When I right click on the form and go to properties - I select the data tab.  In the record source there is a Select statement that was created when I hit the elipsis and chose my desired columns from the table in this database in the Query Builder.  The table is part of the Access database and not excel so that shouldn't be the issue.  Anything else you would like me to check?  Regards,
If you see a select statement as record source, you have a bound form. If your combo also has a field name as control source, then that is bound as well.

If that is the case, each time a new record is reached (including the very first record when opening the form), the combo is updated, and all dependent controls are updated in turn.

What happens is you simply reselect the same entry in the combo? Do the text boxes update at that time?

(°v°)
Hi harfang-  I set the combobox to default to a blank record and it works now.  I have another question regarding this but I will open another thread because I've asked too many questions here.  Thanks for all your help and I gave you credit for this question.

Regards,