Consulting

Results 1 to 4 of 4

Thread: Setfocus on Nested Multipage(s)

  1. #1

    Setfocus on Nested Multipage(s)

    Hi guys,

    Due to poor performance graphics at work I have had to change from a continous userform to multipages with some nested multipages.

    For data validation I need to check if certain items have been checked or not, and if not then send the user back to them for further attention.

    If the item is just on a multipage, then it's simple to do using

    UserForm8.multipage1.Value = 4
    UserForm8.control1.SetFocus

    The problem arises where I need to go a control on a multipage that's on a multipage.

    I would have hoped that the following would have worked, but alas no...

    UserForm8.multipage1.Value = 4 'upper page - 5th tab
    UserForm8.multipage2.Value = 0 'lower page - 1st tab
    UserForm8.control1.SetFocus

    Any help would be greatly appreciated thanks.


    Regards
    Kes

  2. #2
    Without the userform to check it is difficult to be sure, but where TextBox1 is the first control on the first tab of MultiPage2 (which is a multipage form on the fifth tab of MultiPage1) the following certainly works for me.

    MultiPage1.Value = 4
        MultiPage2.Value = 0
        TextBox1.SetFocus
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Hi gmayor,

    Gosh what an idiot I am.

    I was ultimately referencing a radio button inside a frame, which was causing the fault.

    After you said it worked I played with it and got it work by referring to the frame.

    Thanks very much for the quick reply and guidance.


    Regards
    Kes

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,339
    Location
    You can also do this dynamically:

    Private Sub UserForm_Initialize()
      'The textbox of interest located on Page 0 of Multipage2 nexted on Page 0 of Multipage1.
      'Hide it
      MultiPage1.Value = 1
      MultiPage2.Value = 1
      DynamicSetFocus TextBox3
    lbl_Exit:
      Exit Sub
    End Sub
    Sub DynamicSetFocus(oCtrl As Control)
    Dim oParentCtrl As Object
    Dim arrCtrl()
    Dim lngParent As Long, lngIndex As Long
      Set oParentCtrl = oCtrl.Parent
      If oParentCtrl.Name = Name Then
        oCtrl.SetFocus
      Else
        Do Until oParentCtrl.Name = Name
          ReDim Preserve arrCtrl(1, lngParent)
          arrCtrl(0, lngParent) = TypeName(oParentCtrl)
          arrCtrl(1, lngParent) = oParentCtrl.Name
          Set oParentCtrl = oParentCtrl.Parent
          lngParent = lngParent + 1
        Loop
      End If
      For lngIndex = UBound(arrCtrl, 2) To 1 Step -1
        Select Case arrCtrl(0, lngIndex)
          Case "MultiPage"
            Controls(arrCtrl(1, lngIndex)).Value = Controls(arrCtrl(1, lngIndex)).Pages(CStr(arrCtrl(1, lngIndex - 1))).Index
            lngIndex = lngIndex - 1
          Case "Frame"
            Controls(arrCtrl(1, lngIndex)).SetFocus
        End Select
      Next
      'The control's parent is now visible so set focus.
      oCtrl.SetFocus
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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