Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i populate text boxes based upon combo box value?

Status
Not open for further replies.

yehong

Programmer
Sep 22, 2003
291
US
I am using Access 2003. I have two combo boxes (combo1 and combo2) on my form. Combo1 is at the top of the form and when a value is selected, it populates whole form, including combo2, with data based upon that combo1 value. Now in some cases I might need to change a value in combo2. In that case there are three text boxes whose values also should change based upon new value in combo2. Then once I click 'Save' all values should be saved with new values. Is this possible? If my question is not clear please let me know and I will add more details to it. Thanks in advance.
 
Hi, yehong,

Yes, it's pretty easy, actually... But I need a little more info, please. Is the data that's to go in the textboxes located in one or more columns of the combobox? That is, do you want to move data from the combo into the textboxes?

Ken S.
 
Ok. the here is the sample data for combo2:

Name Start Date End Date
State_K1_2005 01/15/2005 01/31/2005
State_K2_2005 02/01/2005 03/31/2005
State_K3_2005 05/15/2005 07/08/2005

The comob2 is showing only the Name column and txtStartDate and txtEndDate have the Start Date and End Date columns.
Now when combo2 values are changed, the text boxes values should also change. Right now text boxes values only change when combo1 value is changed. So when comob1 value is changed, the values of all controls should change,which is working fine, and when value in combo2 is changed only txtStartDate and txtEndDate values should change, which is not working. Hope this helps.
 
Okay, use Column notation. In combo2's AfterUpdate event:
Code:
Me!txtStartDate = Me!combo2.Column(1)
Me!txtEndDate = Me!combo2.Column(2)
This assumes your combo has 3 columns (columns are zero-based).

Ken S.
 
Hi Ken, the comobo2 has only one column, i-e Name.The row source is a simple query, like "Select Name from TableA".
I tried to make the query as "Select Name, StartDate, EndDate from TableA" but it errors when the form tries to load. Since comob2 and both texts need to get populated when the form loads with first record for comob1, I am thinking it may be causing a conflict.
 
Sorry for the misunderstanding, but why did you show 3 columns in your sample data for combo2? What holds StartDate and Endate?

Ken S.
 
Lets assume user selects value in combo1, say STATE_K1, it populates data as follows:

comob1=STATE_K1
txtState=K1
txtcity=City Name txtloc=1234 location name

comob2=State_K1_2005
txtStartDate=01/15/2005 txtEndDate=01/31/2005

Now lets say we just want to change start and end dates, we will select 'State_K2_2005' in the combo2 and hence we want the start and end dates also change to start and end dates for 'State_K2_2005'. After changing this we will hit 'Save' and now STATE_K1 will have new start and end dates. The problem is txtStart and txtEnd are only changing when combo1 is changing, but I want them to also change when I change values in combo2. So the general idea of query for both txts is:
txtStardate=Select StartDate from TableA where Name=combo2.name
txtEndDate=Select EndDate from TableA where Name=combo2.name



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top