Having combobox that toggles visibility populates based on current visible layer

Started by mfm150, April 13, 2017, 04:44:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mfm150

I am creating a userform template for wiring diagrams. 
One option is the platfrom select in a combobox.
I am able to toggle visibility based on which option is selected.  I am also able to populate the combobox upon initilizing the userform however even though the correct platform is selected, by adding this, i lose the ability to toggle visibility.  Can someone point me in the right direction?

PlatformSelect.AddItem ("Onyx Wilder")
PlatformSelect.AddItem ("Onyx Gene (AIO)")
PlatformSelect.AddItem ("Smart TV")
PlatformSelect.AddItem ("Zotac")
PlatformSelect.AddItem ("CN4")
If Application.ActiveWindow.Page.Layers.Item(36).CellsC(visLayerVisible).FormulaU = "1" Then
PlatformSelect.Value = "Onyx Wilder"
Call LayerToggle(36, 1)
Else
If Application.ActiveWindow.Page.Layers.Item(28).CellsC(visLayerVisible).FormulaU = "1" Then
PlatformSelect.Value = "Onyx Gene (AIO)"
If Application.ActiveWindow.Page.Layers.Item(35).CellsC(visLayerVisible).FormulaU = "1" Then
PlatformSelect.ListIndex = "Smart TV"
End If
End If
End If

The if statements being added stops the action below from responding correctly:
(I cut off most of the code because it is redundant but you should get the idea of what it achieves.)
Private Sub PlatformSelect_Change()

If PlatformSelect.Value = "Onyx Wilder" Then
For x = 28 To 49
Call LayerToggle((x), 0)
Next


FWL1.Visible = True
FWL2.Visible = True
FWL3.Visible = True
FWL4.Visible = True
FWL5.Visible = True
FWL6.Visible = True
FWL7.Visible = True
FWL8.Visible = True
IMX.Visible = True
TVSpeaker.Visible = True
VoltageSelect.Visible = True
AIOL1.Visible = False
AIOL2.Visible = False
AIOVBSelect.Visible = False
TVType.Visible = True
KBSelect.Visible = True
PSSelect.Visible = True
CableSelect.Visible = True
HDMISelect.Visible = True
OnOffSelect.Visible = True
PendantSelect.Visible = True
ExtSelect.Visible = True
TVType.Visible = True
KBSelect.Visible = True
PSSelect.Visible = True
CableSelect.Visible = True
HDMISelect.Visible = True
OnOffSelect.Visible = True
PendantSelect.Visible = True
ExtSelect.Visible = True
AIOCableSelect.Visible = False
AIOKBSelect.Visible = False
SML1.Visible = False
SML2.Visible = False
SML3.Visible = False
SML4.Visible = False
SML5.Visible = False
SML6.Visible = False
SMTVSelect.Visible = False
SMCableSelect.Visible = False
SMKBSelect.Visible = False
SMPENDANTSELECT.Visible = False
SMPSSELECT.Visible = False
SMEXTSELECT.Visible = False
SMTVSpeaker.Visible = False


Else


If PlatformSelect.Value = "Onyx Gene (AIO)" Then
Call LayerToggle(28, 1)
Call LayerToggle(29, 0)
Call LayerToggle(30, 0)
Call LayerToggle(31, 0)
Call LayerToggle(32, 0)
Call LayerToggle(33, 0)
Call LayerToggle(34, 0)

FWL1.Visible = False
FWL2.Visible = False
FWL3.Visible = False
FWL4.Visible = False
FWL5.Visible = False
FWL6.Visible = False
FWL7.Visible = False
FWL8.Visible = False
IMX.Visible = False
TVSpeaker.Visible = False
VoltageSelect.Visible = False
AIOL1.Visible = True
AIOL2.Visible = True
AIOVBSelect.Visible = True
TVType.Visible = False
KBSelect.Visible = False
PSSelect.Visible = False
CableSelect.Visible = False
HDMISelect.Visible = False
OnOffSelect.Visible = False
PendantSelect.Visible = False
ExtSelect.Visible = False
AIOCableSelect.Visible = True
AIOKBSelect.Visible = True
SML1.Visible = False
SML2.Visible = False
SML3.Visible = False
SML4.Visible = False
SML5.Visible = False
SML6.Visible = False
SMTVSelect.Visible = False
SMCableSelect.Visible = False
SMKBSelect.Visible = False
SMPENDANTSELECT.Visible = False
SMPSSELECT.Visible = False
SMEXTSELECT.Visible = False
SMTVSpeaker.Visible = False

wapperdude

The "end ifs" aren't properly nested.

If Application.ActiveWindow.Page.Layers.Item(36).CellsC(visLayerVisible).FormulaU = "1" Then
PlatformSelect.Value = "Onyx Wilder"
Call LayerToggle(36, 1)
Else
If Application.ActiveWindow.Page.Layers.Item(28).CellsC(visLayerVisible).FormulaU = "1" Then
PlatformSelect.Value = "Onyx Gene (AIO)"
If Application.ActiveWindow.Page.Layers.Item(35).CellsC(visLayerVisible).FormulaU = "1" Then
PlatformSelect.ListIndex = "Smart TV"
End If
End If
End If


One option, looks like adding some "ElseIf's":


If Application.ActiveWindow.Page.Layers.Item(36).CellsC(visLayerVisible).FormulaU = "1" Then
     PlatformSelect.Value = "Onyx Wilder"
     Call LayerToggle(36, 1)
ElseIf Application.ActiveWindow.Page.Layers.Item(28).CellsC(visLayerVisible).FormulaU = "1" Then
     PlatformSelect.Value = "Onyx Gene (AIO)"
ElseIf Application.ActiveWindow.Page.Layers.Item(35).CellsC(visLayerVisible).FormulaU = "1" Then
     PlatformSelect.ListIndex = "Smart TV"
End If


Note:  you only execute the "call" if the first "if" is successful.  Also "Smart TV" is assigned to "ListIndex", the others get "Value".

Wapperdude
Visio 2019 Pro

mfm150

Hey thanks so much. I was getting an error when selecting Smart tv but I changed it from ListIndex to Value and it is working.  Which I came across this resource when I started !