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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Boxes 1

Status
Not open for further replies.

mrkshpntf

MIS
Apr 19, 2007
92
US
I have two combo boxes.

CBox1 is called "Produce" which has two options in the list: Fruits and Veggies

CBox2 is called "ProduceList" which displays either a list of Fruits or a list of Veggies depending on the selection in CBox1.
When Fruits is selected in CBox1 a list of Fruits is displayed in CBox2 and If Veggies is selected in CBox1 a list of Veggies is displayed in CBox2.

The code looks like this:

Dim Produce As String
Dim ProduceList As String
Dim FruitsList As String
Dim VeggiesList As String


If Me.Produce = "Fruits" Then
Me.ProduceList.RowSource = "FruitsList"
Else
Me.ProduceList.RowSource = "VeggiesList"
End If


The issue is the user selects Fruits or Veggies, the respective list appears in CBox2 but if user changes his/her mind and changes selection from Fruits to
Veggies or vice versa; the original selection continues to populate CBox2 till user clicks back in CBox2.

Is there a way to make the change appear in CBox2 as soon as change is made in CBox1?

Thanks for your help,.

mrkshpntf.
 
you try putting some code in the afterUpdate event of comboboxes?

--------------------
Procrastinate Now!
 

Crowley16,

Thanks for your suggestion but it didn't resolve the issue.

I have tried putting the code in other events like OnDirty, OnChange but it doesn't help.

Thanks,
mrkshpntf.
 
How are ya mrkshpntf . . .

Agree with [blue]Crowley16[/blue], the [blue]AfterUpdate[/blue] event is the way to go (be sure your moving the code and not duplicating it).

If problems presist delete & reconstitute CBx2 . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 


randy700,

Thanks for your help.

Where do I enter "CBox2.Requery"?

mrkshpntf.



 
In the Produce's AfterUpdate event procedure and the Form's Current event procedure:
If Me!Produce = "Fruits" Then
Me!ProduceList.RowSource = "FruitsList"
Else
Me!ProduceList.RowSource = "VeggiesList"
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Randy, changing the RowSource automatically execute the Requery method.
 


PHV,

Thanks for your response.

I already have the code you gave (see above).

My problem is that if a change is made for the second time in CBox1 (i.e. if a user changes his/her mind and changes selection in CBox1)it leads to no change in CBox2 i.e. CBox2 keeps displaying the list corresponding to first selection in CBox1.

mrkshpntf.
 
I already have the code you gave
In which events ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

PHV

In the AfterUpdate event of CBox1 ('Produce').

I tried the code in 'On Current' event too but there is no change for either events.

Thanks,
mrkshpntf.

 
G'day... if you want the list to change as soon as the user selects something in CBox1, you actually need to use the OnChange event. If you use the AfterUpdate event, it won't fire until the user moves away from CBox1, eg, clicking on the list.

Have you tried using the code that PHV supplied above in the OnChange event?

Note that PHV also suggested adding the same code to the form's OnCurrent event. That's useful IF you set a Default value for CBox1, so that when the form is opened, it will show records in the list immediately.

HTH

Max Hugen
Australia
 
Max,

Thanks for your suggestion but it didn't resolve the issue.

What continues to happens is (for example) If I select 'Fruits' in the Produce Combo Box (CBox1), the list of Fruits appears in the ProduceList Combo Box (CBox2).
Now if I select "Apple" from that list in CBox2 and then change the selection CBox1 to Veggies, "Apple" continues to appear in CBox2.

I would like the change to trigger CBox2 to display the first value on the list of Veggies.

Unfortunately this is not happneing.

Thanks for your help!

mrkshpntf.
 
If Me!Produce = "Fruits" Then
Me!ProduceList.RowSource = "FruitsList"
Else
Me!ProduceList.RowSource = "VeggiesList"
End If
Me!ProduceList.SetFocus
Me!ProduceList.ListIndex = 1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 


PHV,

It worked!!

Thanks a lot!!!

Also like to thank all the others (Crowley16; TheAceMan1; Randy700; Max Hugen) who took time to suggest solutions to my problem. Your suggestions are always appreciated!

Thanks guys, you all are always a great help.

mrkshpntf.
 
G'day PHV

I use the above techniques frequently, but I've never had to add:

Me!ProduceList.SetFocus
Me!ProduceList.ListIndex = 1

Have you any suggestions why it didn't work for mrkshpntf without the extra 2 lines above?

Cheers





Max Hugen
Australia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top