Consulting

Results 1 to 6 of 6

Thread: How to select dynamic multipage tab please?

  1. #1

    How to select dynamic multipage tab please?

    Hi fellow VBA'ers

    So...

    I have a userform with 8 tabs.

    To make life easier for my users I want hide hide three of them, unless the are required (reducing clutter).

    But.

    At the end I do error checking to ensure that some mandatory fields have been completed.

    I used to be able to select the blank field by using

    UserForm8.MP1.Value = 5
    UserForm8.MP2.Value = 2
    UserForm8.Frame14.SetFocus

    Now I can't use that method as the value will change depending on how many tabs are displayed.

    I've tried


    UserForm8.MP1.pages ("page6)
    UserForm8.MP2.Value = 2
    UserForm8.Frame14.SetFocus



    But it gives an error, I tried looping through to get an index number with no luck either.

    Your help would be greatly appreciated thanks :-)


    Regards
    Kes

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Well obviously you can't set the focus on a control positioned on a hidden page tab.

    Private Sub UserForm_Initialize()
    Dim lngIndex As Long
      With MultiPage1
        .Value = 0
        .Pages(5).Visible = False
        .Pages(6).Visible = False
        .Pages(7).Visible = False
    On Error GoTo Err_Enabler
        For lngIndex = 0 To MultiPage1.Pages.Count
           If TextBox1 = vbNullString Then
             TextBox1.SetFocus
             Exit For
           End If
        Next
      End With
    lbl_Exit:
      Exit Sub
    Err_Enabler:
      lngIndex = lngIndex + 1
      MultiPage1.Value = lngIndex
      Resume
    End Sub
    Last edited by gmaxey; 07-25-2017 at 05:34 AM.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Hi Greg,

    Sorry for my poor explanation.

    The tabs will be visible as they will be turned on by the end users.

    So I will be going to a visible tab for the validation bit.

    Does that make any difference to you answer?

    Thanks
    Kes

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Not really. The point is that to set focus to a control in a multipage control is that control's parent page must be the enabled page. So it Textbox2 is located on Multipage1.Pages(3) then Page 3 has to be the enabled page.
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    solved.

    Thank you very much!

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Quote Originally Posted by kestrel1306 View Post
    solved.

    Thank you very much!
    You can mark your thread [Solved] by using [Thread Tools] on the menu above your first post
    ---------------------------------------------------------------------------------------------------------------------

    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

Posting Permissions

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