• Moving from Page to Page in UserForm (VBA/Wrd/97)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Moving from Page to Page in UserForm (VBA/Wrd/97)

    • This topic has 9 replies, 4 voices, and was last updated 22 years ago.
    Author
    Topic
    #387545

    I have created a UserForm with multiple pages. There are textboxes on each page. Users complete each textbox and Tab to the next.

    When they reach the last textbox on Page1 they use the mouse to click on Page2. I set the Tab Order so that the first textbox on Page2 is active ready for typing and Tabbing to subsequent textboxes.

    What specifically is required in the Exit event for that last textbox on Page1 to select the first textbox on Page2?

    This is, move from Page1 to Page2 with the keyboard. (I have enabled an accelerator key on the Page tabs but users want to be able to Tab through to the last Page.

    Thanks, Leigh

    Viewing 2 reply threads
    Author
    Replies
    • #676754

      In standard Windows dialogs, you can use Ctrl+Tab to go to the next tab; I don’t know if the TabStrip or MultiPage controls enable this behavior.

      Personally, I get really confused trying to design forms with multiple layers of controls, so I usually make several UserForms and use a Next button, Wizard style, if I need people to navigate multiple pages.

      • #676765

        Thanks for your reply. The users are currently happy to stay with the Windows dialog box standard ‘Tab’ key behaviour (ie the focus moves to the next control in the Tab Order).

        Whilst I appreciate your comments about the possible complexity of forms with either MultiPages or TabStrips (or a combination of both) in this example it should be simple with only 5 textboxes on ‘Page 1’ and four on ‘Page 2’. The users are happy to stay with the seemingly consistent use of the Tab key and all I want to do is to allow that to happen and using ‘Enter’ to finish with the form. (Assuming the following controls, this is the code I have looked at so far – without success.) A group of textboxes named txtBox1 -5 on Page1 of two pages in a MultiPage called mpPage. Page2 has textboxes named txtBox6, txtBox7 – 9. There are the standard Cancel and OK command buttons with cmdOK being the default. These are placed on the userform and not on the MultiPage control.

        [indent]
        Private Sub txtBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean) mpPage.Pages(1).????? 'code to activate second page? txtBox6.SetFocus End Sub
        [/indent]

        As you can see what I am trying to do is shift the focus to the textbox at the top of Page2 when the user has completed the details in the last textbox on Page1 and pressed the ‘Tab’ key. If the Help system explains this, I have not been able to locate it, nor have I been able to find any suitable advice in these two references, “Word 97 Macro & VBA Handbook” an otherwise excellent reference and “Mastering VBA” both by Guy Hart-Davis.

        I’m stuck – maybe I am not on the right path with the Exit sub to leave the textbox on Page1?

    • #676763

      I assume you’re talking about using a MultiPage control on a UserForm. This has multiple tabs with default names Page1, Page2, etc. With the various controls (check boxes, text boxes, etc.) on each page you have set the tabs to go to each control in sequence. For the last control on a given page, you generally need a Next button which would then display the next Page and then you can set focus to the first control on that page.

      The Exit event for your last control (text box you said) on Page1 won’t work in this case since there is no place for it “exit to” (no next control on the same page). I’m trying to say that the Exit only works when the user exits the text box and since there is no place for the user to exit to (unless they press Enter not a tab as you want) I don’t think the Exit event will do what you want. You could test for keystroke=tab and the current control is your text box (the last one).If these two are true then enable the Page2.

      The downside of not having a Next button is that the user is forced to go to Page2 even if they didn’t want to. If they entered the wrong text in your last text box and pressed Enter your code would force them to go to Page2. They’d they need to get back to Page1 to fix their error. This is quite irritating to the user. You can use the Enter property on the text box to set the ‘next’ button as focus and then they can press Enter to go to Page2. This way they can tab from your last text box to the Next button which then takes them to Page2.

      If your goal is to not use a Next/Previous button then I believe you’re making quite a non-standard tab field and irritating to the user if you automatically take them to the next Page without a way to confirm what they entered on the text box is correct. 2cents

      Deb

      • #676769

        Thank you Deb, I just posted a reply to jscher2000’s response when your response to my problem came in.

        What I am trying to achieve is what you mention at the end of your second para. ” …then enable the Page2.”

        I do not want to use a button to move to the next page as the users can use the ‘Alt+2’ accelerator that I set. I really wanted to use the Tab key as a continuation from textbox to textbox (the reason for the two pages is to give the users sufficiently large textboxes to review their typed responses, and as such, it meant the form would be too large for the screen – hence splitting into two pages). BTW, each textbox has EnterKeyBehaviour set to ‘True’ as there can be multiple paragraphs in each of their responses.

        Unless there are other ways to have lots of textboxes on the form, I am stuck with the use of the accelerator option. At least the users can keep their hands on the keyboard and not have to reach for the mouse to activate the second page.

        Still trying, Leigh

        • #676770

          Ah, ok so you need to know how in code to enable Page2. bingo Like this:

          me.MultiPage.Value = pageID

          pageID is an integer which is set on the property for the page. The field is called ‘Index’ and Page1’s Index=0.

          For the app I wrote that had a MultiPage control (and 12 tabs/pages) I set a bunch of Public constants to the various page indexes.

          Deb flatcat

          • #676774

            Sorry Deb, tried that very early in the piece but it did not show Page2, but a mouse click in the textbox AFTER pressing Tab showed Page2 but the focus was not in the desired first textbox but elsewhere. Thought I was on the right track but couldn’t get the focus to be where needed. (Other than tabbing, how do you determine where the focus is?)
            Thanks, Leigh

            • #676776

              Hhhmmm, well I know that .Value = next_page_index does work to display the specified tab page (doesn’t have to be the ‘next’ one, just the one with the Index value specified).

              So you can get to the next tab apparently but the focus isn’t on the control you want. I’d check the tab settings for those controls since by default it’ll go to the next tab sequence in order. You can add code on the Page2_Activate() event (I don’t remember the name as I don’t have my project open now) and then set the focus for the control you want.

              Ok… 15 minutes has passed…. I went back and tried it and got it working. I used the MultiPage_change() event to force the first textbox on Page2 to be in focus when user hit the accelerator key (to go to page2).

              Private Sub MultiPage1_Change()
                If Me.MultiPage1.Value = 1 Then     ' page2
                  Me.TextBox2.SetFocus
                  Me.TextBox2.Text = "here I am"
                End If
                
              End Sub
              
              Private Sub UserForm_Initialize()
                Me.MultiPage1.Value = 0     ' shows page1 on load
              End Sub

              My UserForm has one two tabbed MultiPage. Page1 has a checkbox, and a textbox (#1). Page2 has two textboxes (#2, #3)

              Is that what you need? bouncenburn

              Deb

        • #676773

          (Edited by jscher2000 on 15-May-03 00:04. Added a little picture and a comment in the first procedure.)

          Okay, first of all, this MultiPage thing is easier than I remembered. Nice.

          Second, all you need to do is have the “next page” button respond to being tabbed into:

          Private Sub btnNext_Click()
          ‘ This next line actually is superfluous if you run the same command in the _Enter event handler
          GoToPageNext Me.MultiPage1
          End Sub

          Private Sub btnNext_Enter()
          GoToPageNext Me.MultiPage1
          End Sub

          Sub GoToPageNext(mp As MultiPage)
          mp.Value = mp.Value + 1
          End Sub

          This gives your users the click or tab choice. (Special thanks to post 194854 for that code to advance to the next page.)

    • #676812

      hi Leigh,

      assuming textbox2 is the last textbox on the first page, the following code will move to the next page with focus on the first control of that page :

      Private Sub TextBox2_KeyDown _
      ( _
      ByVal KeyCode As MSForms.ReturnInteger, _
      ByVal Shift As Integer _
      )
      If KeyCode = 9 Then MultiPage1.Value = 1
      End Sub

      be aware that this will trigger the change event of the multipage, so any code you have placed in that event handler could possibly interfere with the first textbox receiving focus. you could create a userform level boolean variable to prevent any code in the multipage change event from being executed :

      private NoMPChangeEvent as boolean

      Private Sub TextBox2_KeyDown _
      ( _
      ByVal KeyCode As MSForms.ReturnInteger, _
      ByVal Shift As Integer _
      )
      If KeyCode = 9 Then
      NoMPChangeEvent=true
      MultiPage1.Value = 1
      NoMPChangeEvent =false
      end if
      End Sub

      Private Sub MultiPage1_Change()
      if NoMPChangeEvent then exit sub
      ‘rest of your code
      End Sub

      greetings,

    Viewing 2 reply threads
    Reply To: Moving from Page to Page in UserForm (VBA/Wrd/97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: