PDA

View Full Version : VBA reset all pages in multipage



boegie
07-30-2018, 10:43 AM
Hi all,

I'm working on a userform. When changing a certain optionbutton, the userform should reset all pages of a multipage.

I tried reset/ multipage.pages().controls.clear/...

nothing seems to work. Who can help me with the code please?

Thanks!

Paul_Hossler
07-30-2018, 11:11 AM
Not sure about what 'reset' exactly means since it's not a VBA method as far as I can see

UserForm1 has MultiPage1 on it with Page1..Page5

HTH




Option Explicit
Sub drv()


Load UserForm1

Dim i As Long
For i = 0 To UserForm1.MultiPage1.Pages.Count - 1
Select Case i
Case 0
MsgBox "Resetting " & UserForm1.MultiPage1.Pages(i).Caption
Case 1
MsgBox "Resetting " & UserForm1.MultiPage1.Pages(i).Caption
Case 2
MsgBox "Resetting " & UserForm1.MultiPage1.Pages(i).Caption

'etc.

End Select

Next i
UserForm1.Show
End Sub

boegie
07-30-2018, 11:14 AM
Thanks for your reply Paul!

I want to clear all pages on the multipage (textboxes, optionbuttons and checkboxes).

I have a button, when you click the button, the vba should erase the multipage.

Paul_Hossler
07-30-2018, 12:53 PM
Maybe this then, but .Clear only works for controls added at run time

Otherwise you'd probably have to loop the Pages and then loop the Controls with .Delete





Option Explicit

Sub drv()


Load UserForm1

Dim i As Long
For i = 0 To UserForm1.MultiPage1.Pages.Count - 1
UserForm1.MultiPage1.Pages(i).Clear
Next I

UserForm1.Show
End Sub


PS -- Not tested

mikerickson
07-31-2018, 10:56 AM
Are you looking for something like


Dim onePage As MSForms.Page
Dim oneControl As MSForms.Control, i As Long

For Each onePage In MultiPage1.Pages
For Each oneControl In onePage.Controls
Select Case TypeName(oneControl)
Case "CheckBox", "OptionButton"
oneControl.Value = False
Case "TextBox", "RefEdit"
oneControl.Text = vbNullString
Case "ComboBox", "ListBox"
If oneControl.MultiSelect <> fmMultiSelectSingle Then
With oneControl
For i = 0 To .ListCount - 1
.Selected(i) = False
Next i
End With
Else
oneControl.ListIndex = -1
End If
End Select
End Select
Next oneControl
Next onePage