?
Solved

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

Posted on 2007-10-15
8
Medium Priority
?
1,622 Views
Last Modified: 2013-11-28
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.
0
Comment
Question by:joshinh
  • 4
  • 2
  • 2
8 Comments
 
LVL 58

Expert Comment

by:harfang
ID: 20082566
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°)
0
 

Author Comment

by:joshinh
ID: 20085049
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,
0
 
LVL 58

Accepted Solution

by:
harfang earned 200 total points
ID: 20086949
No need for VB. The expressions are entered directly as Control Source of the text boxes. The form engine will notice the dependency (because you use the name Combo0 in the expression) and both will be re-evaluated every time Combo0 changes.

With the event you used, they would get updated only when you change the value in Combo0, not when you surf to a new record, not when you undo your changes, not if some other codes changes the value, etc.

Also, Column Widths contains a list of widths, separated by semi-colons. You want

    ;0";0"

... hiding the second and third column. Your setting of 0" hides the first column.

Good luck!
(°v°)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:joshinh
ID: 20088582
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.
0
 
LVL 58

Expert Comment

by:harfang
ID: 20089451
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°)
0
 

Expert Comment

by:JoshinHtown
ID: 20094299
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,
0
 
LVL 58

Expert Comment

by:harfang
ID: 20094917
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°)
0
 

Expert Comment

by:JoshinHtown
ID: 20095058
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,
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question