Consulting

Results 1 to 5 of 5

Thread: VBA reset all pages in multipage

  1. #1
    VBAX Newbie
    Joined
    Jul 2018
    Posts
    2
    Location

    VBA reset all pages in multipage

    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!

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    Jul 2018
    Posts
    2
    Location
    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.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •