Multipage Pages will not show controls when enabled

R

RyanH

I have a UserForm with a Combobox named "cboIllumination" and a MultiPage
name "mpgIllumination". When the UserForm is Intialized all the pages in the
mpgIllumination.Enabled = False and cboIllumination.ListIndex = 0.
Here is the problem. As the user changes cboIllumation I want the
associated page in mpgIllumination to be enabled and display the controls in
it. The code below will enable the page, but the controls are not visible
until I select it, why? Is it possible to make sure the controls are visible
when the pages enable property = True.

Private Sub cboIllumination_Change()

Dim pg As Page

'disables all three pages
For Each pg In mpgIllumination.Pages
pg.Enabled = False
Next pg

'enables the associated page that was selected in listbox
If cboIllumination.ListIndex <> 0 Then
With mpgIllumination.Pages(cboIllumination.ListIndex - 1)
.Enabled = True
.Visible = True
End With
End If

End Sub
 
D

Dave Peterson

I created a small userform with a combobox on it with 3 entries. I added a
multipage with 3 pages.

I wanted the first item in the combobox to control page0, the 2nd item to
control page1 and the 3rd item to control page2. That seems different from what
you used. (You checked for <> 0. 0 represents the first item in the combobox
list.) Did you mean that???

Anyway....

Your code worked ok for me.

Maybe adding
Me.Repaint
to the end of that procedure will make it work ok for you. (I didn't need it,
though.)

Private Sub cboIllumination_Change()
Dim pg As Page
'disables all three pages
For Each pg In Me.mpgIllumination.Pages
pg.Enabled = False
Next pg

'enables the associated page that was selected in listbox
If Me.cboIllumination.ListIndex < 0 Then
'do nothing
Else
With Me.mpgIllumination.Pages(Me.cboIllumination.ListIndex)
.Enabled = True
.Visible = True
End With
End If

Me.Repaint

End Sub

Another method:

Private Sub cboIllumination_Change()
Dim iCtr As Long
If Me.cboIllumination.Value < 0 Then
Exit Sub
Else
With Me.mpgIllumination
For iCtr = 0 To .Count - 1
.Pages(iCtr).Visible = True 'CBool(iCtr =
Me.cboIllumination.ListIndex)
.Pages(iCtr).Enabled = CBool(iCtr =
Me.cboIllumination.ListIndex)
Next iCtr
End With
End If
End Sub
 
R

RyanH

Yes I did mean to do that. These are the items in cboIllumination when the
Userform is Initialized. I have set the enable property for each page of the
mpgIllumination = False. So when "Single Row T12 HO Fluorescents" is
selected Page(0) should be enabled and the controls on that page should be
visible, but they are not. The Page enables, but the controls are not
visible until I click the Page Tab, then they appear. Then Me.Repaint did
not seem to work. Any other ideas or suggestions?

UserForm_Initialize()

With cboIllumination
.AddItem "No Illumination"
.AddItem "Single Row T12 HO Fluorescents"
.AddItem "Single Row T8 HO Fluorescents"
.AddItem "LEDs"
End With

End Sub

Private Sub cboIllumination_Change()

Dim pg As Page

'disables all three pages
For Each pg In mpgIllumination.Pages
pg.Enabled = False
Next pg

'enables the associated page that was selected in listbox
If cboIllumination.ListIndex > 0 Then
With mpgIllumination.Pages(cboIllumination.ListIndex - 1)
.Enabled = True
.Visible = True
End With
End If

Me.Repaint

End Sub
--
Cheers,
Ryan


Dave Peterson said:
I created a small userform with a combobox on it with 3 entries. I added a
multipage with 3 pages.

I wanted the first item in the combobox to control page0, the 2nd item to
control page1 and the 3rd item to control page2. That seems different from what
you used. (You checked for <> 0. 0 represents the first item in the combobox
list.) Did you mean that???

Anyway....

Your code worked ok for me.

Maybe adding
Me.Repaint
to the end of that procedure will make it work ok for you. (I didn't need it,
though.)

Private Sub cboIllumination_Change()
Dim pg As Page
'disables all three pages
For Each pg In Me.mpgIllumination.Pages
pg.Enabled = False
Next pg

'enables the associated page that was selected in listbox
If Me.cboIllumination.ListIndex < 0 Then
'do nothing
Else
With Me.mpgIllumination.Pages(Me.cboIllumination.ListIndex)
.Enabled = True
.Visible = True
End With
End If

Me.Repaint

End Sub

Another method:

Private Sub cboIllumination_Change()
Dim iCtr As Long
If Me.cboIllumination.Value < 0 Then
Exit Sub
Else
With Me.mpgIllumination
For iCtr = 0 To .Count - 1
.Pages(iCtr).Visible = True 'CBool(iCtr =
Me.cboIllumination.ListIndex)
.Pages(iCtr).Enabled = CBool(iCtr =
Me.cboIllumination.ListIndex)
Next iCtr
End With
End If
End Sub
 
D

Dave Peterson

I don't have another guess.

The controls on the multipage pages showed up ok for me in my testing.

Any chance that it's a display problem--does the userform work ok on a different
pc?

If it does, maybe you can tweak a display setting????? (Like lowering the
hardware acceleration of the video card???)

Keep track of any existing settings so that you can turn them back to what they
were before you started tweaking!
Yes I did mean to do that. These are the items in cboIllumination when the
Userform is Initialized. I have set the enable property for each page of the
mpgIllumination = False. So when "Single Row T12 HO Fluorescents" is
selected Page(0) should be enabled and the controls on that page should be
visible, but they are not. The Page enables, but the controls are not
visible until I click the Page Tab, then they appear. Then Me.Repaint did
not seem to work. Any other ideas or suggestions?

UserForm_Initialize()

With cboIllumination
.AddItem "No Illumination"
.AddItem "Single Row T12 HO Fluorescents"
.AddItem "Single Row T8 HO Fluorescents"
.AddItem "LEDs"
End With

End Sub

Private Sub cboIllumination_Change()

Dim pg As Page

'disables all three pages
For Each pg In mpgIllumination.Pages
pg.Enabled = False
Next pg

'enables the associated page that was selected in listbox
If cboIllumination.ListIndex > 0 Then
With mpgIllumination.Pages(cboIllumination.ListIndex - 1)
.Enabled = True
.Visible = True
End With
End If

Me.Repaint

End Sub
 
R

RyanH

I tried on two other computers, even tried redrawing a new userform and I
still have the issue. The Page is enabled, but the controls in the page do
not show until I select the enabled tab. Is there code that you know of that
will select a tab?


--
Cheers,
Ryan


Dave Peterson said:
I don't have another guess.

The controls on the multipage pages showed up ok for me in my testing.

Any chance that it's a display problem--does the userform work ok on a different
pc?

If it does, maybe you can tweak a display setting????? (Like lowering the
hardware acceleration of the video card???)

Keep track of any existing settings so that you can turn them back to what they
were before you started tweaking!
 
D

Dave Peterson

me.multipage1.value = 2

will select the 3rd page (0, 1, 2, ...)


I tried on two other computers, even tried redrawing a new userform and I
still have the issue. The Page is enabled, but the controls in the page do
not show until I select the enabled tab. Is there code that you know of that
will select a tab?
 
D

Dave Peterson

I really don't understand why your posted code didn't work for you when it
worked for me.

But that's not important <vbg>.
You are a genius. It works just as it should. Thanks for sticking with it
Dave.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top