Immediately Show or Hide Multipage tab based upon checkbox selecti

L

Lyle

I am trying to make the Visible property of a page in a multipage be
dependent upon a checkbox, so that if the checkbox is checked, the page is
visible, and if the checkbox is not checked, then the page is not visible. I
would like it to take effect as soon as the checkbox is selected instead of
having to press a command button for it to take effect. Can this be done?
If so, please share what code is needed to make it happen. Thanks in advance
for any help.
 
O

Ol

I had similar problem in my past expirience. Here is some code

First you need to create new class. Lets name it OverPoweredCheckboxes:

Public WithEvents Ch As msforms.CheckBox
Private Sub Ch_Click()
With MyFormName.SelectedItem
If .ActiveControl Is Nothing Then Exit Sub
If .ActiveControl.Value Then
'Do somthing if checked
Else
'Do somthing if unchecked
End if
End With
End Sub

Second u need to create "overpowered" checkboxes before u called method Show
of your form. You cant place them on form just like ordinary checkboxes.
In global variables section:
Public MyMightyCheckbox As OverPoweredCheckboxes

somewhere in your module:
Sub FormPreparationBeforeShowMethodIsCalled()
Set MyMightyCheckbox = New OverPoweredCheckboxes
Set MyMightyCheckbox.Ch = YourFormName.Controls.Add("Forms.CheckBox.1")

'You have to specify position and initiale state too:

With MyMightyCheckbox.Ch
.Value = True
.Caption = "sdfasd"
.Font.Size = 10
.Left = 10
.Top = 15
.Height = 18
.Width = 340
End With

End Sub

....
FormPreparationBeforeShowMethodIsCalled
YourFormName.Show
....
 

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