Combo Box Code Issue

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hello I have the following code in the on change command
of my Combo Box:


If Combo2.Value = "Main Systems (SIMS,Logon,EPIX etc)" Then
frmSearchMain.Visible = True
Else
frmSearchMain.Visible = False

If Combo2.Value = "CISCO" Then
frmCISCOSearch.Visible = True
Else
frmCISCOSearch.Visible = False

If Combo2.Value = "External Information (EMS Online etc)"
Then
frmExternalSearch.Visible = True
Else
frmExternalSearch.Visible = False
End If
End If
End If


Why is it not working? Is there any way it could be
solved? Its is actually working but I only see the first
form I select from the list.

For example if I select CISCO I get the CISCO Search form
up and then if I select the main info one after using the
CISCO form, and well it still shows me the CISCO form but
when I re jigged the forms around I found it was making
the form visible it was not hiding the CISCO one?

Any Suggestions?

Many Thanks

James
 
Hi James,

I think you have a problem with your nested If's:

Change the formatting and perhaps you can see the problem (if the formatting
is not botched by line wrapping in your newsreader!):

If Combo2.Value = "Main Systems (SIMS,Logon,EPIX etc)" Then
frmSearchMain.Visible = True
Else
frmSearchMain.Visible = False
If Combo2.Value = "CISCO" Then
frmCISCOSearch.Visible = True
Else
frmCISCOSearch.Visible = False
If Combo2.Value = "External Information (EMS Online etc)" Then
frmExternalSearch.Visible = True
Else
frmExternalSearch.Visible = False
End If
End If
End If

If is the first one, there is no code to hide the others - I'd suggest you
modify the code to use a Select Case statement:

Select Case me.combo2
case "Main Systems (SIMS,Logon,EPIX etc)"
frmSearchMain.visible=true
frmCISCOSearch.Visible = False
frmExternalSearch.Visible = False
case "CISCO"
frmSearchMain.visible=False
frmCISCOSearch.Visible = true
frmExternalSearch.Visible = False
case "External Information (EMS Online etc)"
frmSearchMain.visible=false
frmCISCOSearch.Visible = False
frmExternalSearch.Visible = true
end select

Better yet this can be reduced to 3 statements:

frmSearchMain.visible=(me.Combo2.Value = "Main Systems (SIMS,Logon,EPIX
etc)" )
frmCISCOSearch.visible=(me.Combo2.Value = "CISCO" )
frmExternalSearch.visible=(me.Combo2.Value = "External Information (EMS
Online etc)" )
 
Try using the AfterUpdate event instead. According to the
VB Help file, "The Change event doesn't occur when a value
changes in a calculated control or when you select an item
from the combo box list." Also, try changing your code to:

Select Case combo2.Value
Case "Main Systems (SIMS,Logon,EPIX etc)"
frmSearchMain.Visible = True
frmCISCOSearch.Visible = False
frmExternalSearch.Visible = False
Case "CISCO"
frmSearchMain.Visible = False
frmCISCOSearch.Visible = True
frmExternalSearch.Visible = False
Case "External Information (EMS Online etc)"
frmSearchMain.Visible = False
frmCISCOSearch.Visible = False
frmExternalSearch.Visible = True
End Select

Hope this helps!
 
Many thanks

It works....

Cheers

James
-----Original Message-----
Try using the AfterUpdate event instead. According to the
VB Help file, "The Change event doesn't occur when a value
changes in a calculated control or when you select an item
from the combo box list." Also, try changing your code to:

Select Case combo2.Value
Case "Main Systems (SIMS,Logon,EPIX etc)"
frmSearchMain.Visible = True
frmCISCOSearch.Visible = False
frmExternalSearch.Visible = False
Case "CISCO"
frmSearchMain.Visible = False
frmCISCOSearch.Visible = True
frmExternalSearch.Visible = False
Case "External Information (EMS Online etc)"
frmSearchMain.Visible = False
frmCISCOSearch.Visible = False
frmExternalSearch.Visible = True
End Select

Hope this helps!

.
 
I would use a Select Case statement instead of nested If's.
I try to avoid nested If's whenever possible!


'First, set all to False

frmSearchMain.Visible = False
frmCISCOSearch.Visible = False
' (etc)
'Then use the Select Case

Select Case Combo2.value
case "Main Systems (SIMS,Logon,EPIX etc)"
frmSearchMain.Visible = True
case "CISCO"
frmCISCOSearch.Visible = True
'(etc)
End Select
 
Back
Top