05-28-10, 17:59 #1Registered User
- Join Date
- May 2010
Unanswered: Auto Fill Text Fields Based on Combo Box
Okay, I am a complete noob when it comes to VBA and Access so please take it easy!
I'm trying to fill in a few text boxes with information based on a selection from a combo box. I have been searching for examples the past week and have gotten nowhere.
I'll try to explain what I'm looking for as best I can.
I have these text boxes;
City, State, Country and SiteID
I also have the corresponding combo boxes.
I am looking to pull data from my "MAIN" table with the columns "CITY, STATE, COUNTRY, SITEID".
If the combo box for "city" is changed to... "Detroit" I would like it to auto fill "Country, State and SiteID" into the corresponding text boxes from my table.
How can I do this?
I attached a screenshot that may help.
05-30-10, 08:39 #2Registered User
- Join Date
- Jan 2009
- Kerala, India
Auto Fill Text Fields Based on Combo Box
You can create a single Combox using the base table with all the required values in different Columns, SiteID as the first Column and Control Source can be the SiteID field on the Form.
When you click on a line in the Combobox to select the SiteId, the Click-Event can run a VBA Routine to extract other values from the Combox in different columns on the same line of the SiteId selected and insert them into their respective fields on the Form.
Take a look at the following link for an example with VBA Code:
LEARN MS-ACCESS TIPS AND TRICKS Blog Archive Combo-Box Column Valueswww.MsAccessTips.com (Learn MS-Access Tips & Tricks)
Learn Advanced MS-Access Programming with sample VBA Code.
All responses are based on Access 2003/2007
05-30-10, 22:54 #3Moderator
Provided Answers: 19
- Join Date
- Jun 2005
- Richmond, Virginia USA
Set up your combobox using the wizard and include the fields you need, from Left-to-Right.
If in the Combobox they appear as
CITY, STATE, COUNTRY, SITEID
the code would be
Private Sub YourComboBoxName_AfterUpdate() Me.txtCity = Me.YourComboBoxName.Column(0) Me.txtState = Me.YourComboBoxName.Column(1) Me.txtCountry = Me.YourComboBoxName.Column(2) Me.txtSiteID = Me.YourComboBoxName.Column(3) End SubHope this helps!
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007