Page 1 of 3 123 LastLast
Results 1 to 15 of 40
  1. #1
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Setting the Focus in a User Form (VBA/Word/2000)

    I have created a userform and would like to set the focus for the first text box in the form, rather than forcing the user to click in the text box.
    I thought all I'd need to do was set the statement
    ProdTitle.SetFocus
    after the userform.show statement....
    ha!
    any suggestions?
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    In the form code module, create

    Private Sub UserForm_Initialize()

    and put your SetFocus statement in there. The problem with having it in the main code module is that it doesn't run until the UserForm has been dismissed. (Unless I am terribly confused.)

  3. #3
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    Then how do I get the AutoNew function to find the private sub for the form? If I move the initialize statement into the Forms' code the autonew function does not find it?

    Thanks

    p.s. this just shows you that nobody tells the whole story the first time. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    Your AutoNew works exactly as it did before, don't change a thing, just add this event handler in the code for the form so that when it loads itself, it sets the focus:

    Private Sub UserForm_Initialize()
    Me.ProdTitle.SetFocus
    End Sub

  5. #5
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    is me significant?

    'cause I'm still not focussed <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    Catherine,

    The "Me" is a keyword that can be used to refer to the UserForm object itself - you can only use this though in the userform's own private code module.
    So for instance "Unload Me".

    The SetFocus statement should be working (not sure why it isn't), but here's a different way that may avoid the need to use the UserForm_Initialize procedure altogether: just ensure that the ProdTitle textbox is the first item in the userform's Tab Order.
    To set this:
    Click anywhere in the Userform.
    Click on View > Tab Order.
    This will display a Tab Order dialog.
    Use the buttons to move "ProdTitle" to first in the list.

    When you then "show" the userform, the focus should be go to the ProdTitle textbox.

    Gary

  7. #7
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    No luck
    would the fact that it is a Multipage userform have an effect?

    Thanks
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    Me is not needed in self-references.

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    Yes, the multipage form has an effect on what gets displayed.

    You also have to specify which page gets displayed.

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    Sure, but I need to type Me. to get the intellisense prompts. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    You can just type the control name to get the prompts.

  12. #12
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    Ok - this is what it looks like now - and it is still not working.

    Private Sub UserForm_Initialize()
    UserForm1.MultiPage1.SetFocus
    UserForm1.ActiveControl.SetFocus
    UserForm1.ProdTitle.SetFocus

    End Sub
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  13. #13
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    But "me" gives you the control names.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  14. #14
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    If I'm following the discussion correctly then I can refer to the userform either by name or me?
    ie
    me.prodtitle.setfocus
    or
    userform1.prodtitle.setfocus

    except neither work.
    What would I do with a multipage form to activate it?

    thanks.
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  15. #15
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting the Focus in a User Form (VBA/Word/2000)

    ... Or even prodtitle.setfocus

    But you may have to activate the page of the form on which the textbox resides in order to setfocus. Do this by setting the Value propery of the control to the page number (starting from 0)
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

Page 1 of 3 123 LastLast

Posting Permissions

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