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!

Simple question on Combo box 1

Status
Not open for further replies.

Zeroanarchy

Technical User
Jun 11, 2001
630
AU
Hi all thanks for your time on this simple prob, I am trying to run the below code on change of value in the combo box and it does nothing. anyone got any ideas??

properties
style - 2 Dropdown list
datafield - Blank
dataformat - Blank
datamember - blank
datasource - blank
item data - Weeds of National Significance
Chemical Controls
Mechanical Controls
Risk Rating
Selected Contractors and so on...

Private Sub Combo1_Change()
If Combo1.Index = "Weeds of National Significance" Then
Picture10.Visible = True
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False
Picture8.Visible = False
Picture9.Visible = False
Picture1.Visible = False
If Combo1.Index = "Chemical Controls" Then
Picture1.Visible = True
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False
Picture8.Visible = False
Picture9.Visible = False
Picture10.Visible = False
If Combo1.Index = "Mechanical Controls" Then
Picture1.Visible = False
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture7.Visible = False
Picture8.Visible = False
Picture9.Visible = False
Picture10.Visible = False
Picture6.Visible = True
If Combo1.Index = "Risk Rating" Then
Picture1.Visible = False
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False
Picture8.Visible = False
Picture10.Visible = False
Picture9.Visible = True
If Combo1.Index = "Selected Contractors" Then
Picture1.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False
Picture8.Visible = False
Picture9.Visible = False
Picture10.Visible = False
Picture2.Visible = True
If Combo1.Index = "Outcome Of Controls By Species" Then
Picture1.Visible = False
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture8.Visible = False
Picture9.Visible = False
Picture10.Visible = False
Picture7.Visible = True
If Combo1.Index = "Enviro Report By Species" Then
Picture1.Visible = False
Picture2.Visible = False
Picture3.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False
Picture8.Visible = False
Picture9.Visible = False
Picture10.Visible = False
Picture4.Visible = True
If Combo1.Index = "Registered Weed Infestations By Species" Then
Picture1.Visible = False
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False
Picture9.Visible = False
Picture10.Visible = False
Picture8.Visible = True
If Combo1.Index = "Registered Weeds By Location" Then
Picture1.Visible = False
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture6.Visible = False
Picture7.Visible = False
Picture8.Visible = False
Picture9.Visible = False
Picture10.Visible = False
Picture5.Visible = True
If Combo1.Index = "Costs By Species" Then
Picture1.Visible = False
Picture2.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False
Picture8.Visible = False
Picture9.Visible = False
Picture10.Visible = False
Picture3.Visible = True


Thanks
[afro]ZeroAnarchy
Experience is a wonderful thing. It enables you to recognize a mistake
when you make it again.

 
I don't think that you can store strings in ItemData.
But if the combobox List property contains the items then this code will work fine.

If Combo1.Text = "Weeds of National Significance" Then
......
 
1) Either put this picture changing in the Combo1_Click event or add "Call Combo1_Change" to the Combo1_Click event.
2) On the data you put into the Itemdata property, I believe you mean you put it into the List property, if not then you need to.
3) You need to be checking the combo box with something like this:
If Combo1.List(Combo1.ListIndex) = "Weeds of National Significance" Then
show this picture here...
elseif Combo1.List(Combo1.ListIndex) = "Chemical Controls" Then
show this picture here...
...
...
...
endif


Hope this helps
 
moreCA thankyou very much just the answer i was looking for. have a star for your quick response and great answer.

Cheers

[afro]ZeroAnarchy
Experience is a wonderful thing. It enables you to recognize a mistake
when you make it again.

 
Thank you very much ZeroAnarchy.

I would make a change to my code if I were writing it...

Change "Combo1.List(Combo1.ListIndex)" to "Combo1.Text"

as bridamol suggested...don't know which is more efficient, but this sure does read a lot easier.
 
Since the code is setting all of the picture boxes to invisible, except for one, that one being dependent on the combo selection, I would suggest turning all boxes to invisible, and turning on on the correct one, and I would prefer the case statement to the cascading if-then-else statement.
Code:
Picture1.Visible = False
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False
Picture8.Visible = False
Picture9.Visible = False
Picture10.Visible = False
Select Case Combo1.Text
   Case "Weeds of National Significance"
      Picture10.Visible = True
   Case "Chemical Controls"
      Picture1.Visible = True
   Case "Mechanical Controls"
      Picture1.Visible = True
and so forth for the reset of the list. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top