Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Is it possible to set the focus on a specific tab on a tab control via VBA? My goal is to set the focus to the tab when the form opens.

    Different iterations of Me.TabCtl0.Pages.Page1.SetFocus doesn't work. I am unable to find the correct syntax to reference the tab.

    Thanks in advance for your ideas.

    Ken

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You have to set the Value of the tab control. The value is the zero-based index of the active tab page. Setting it to 0 activates the first page, setting it to 1 activates the second page, etc.

    So if you want to set focus to the fourth tab page, you'd use

    Me.TabCtl0.Value = 3

  3. #3
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='799410' date='22-Oct-2009 14:27']You have to set the Value of the tab control. The value is the zero-based index of the active tab page. Setting it to 0 activates the first page, setting it to 1 activates the second page, etc.

    So if you want to set focus to the fourth tab page, you'd use

    Me.TabCtl0.Value = 3[/quote]
    Thanks Hans.

    Where do you find documentation for things like that?

    Having asked that, using the above sets the focus on the first control on the tab. I am trying to actually get the tab itself to have the focus and not the first field on the tab. Is that possible?

    Thanks for your help.



    Ken

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    > Where do you find documentation for things like that?

    In the Access VBA help.

    > I am trying to actually get the tab itself to have the focus and not the first field on the tab. Is that possible?

    Don't think so.

  5. #5
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='799415' date='22-Oct-2009 14:44']> Where do you find documentation for things like that?

    In the Access VBA help.

    > I am trying to actually get the tab itself to have the focus and not the first field on the tab. Is that possible?

    Don't think so.[/quote]
    Hans,

    Using the Me.TabCtl0.Value = 3 in the on open event, I can hit Control Tab once the form opens and the tab is highlighted/has the focus. Is there a way to send shift tab after the Me.TabCtl0.Value = 3?

    Sorry to be so dense.

    Thanks,

    Ken

  6. #6
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='799415' date='22-Oct-2009 14:44']> Where do you find documentation for things like that?

    In the Access VBA help.

    > I am trying to actually get the tab itself to have the focus and not the first field on the tab. Is that possible?

    Don't think so.[/quote]
    Hans,

    I tried setting the focus to a control on the form header, then Me.TabCtl0.Value = 3. Voila', I get the results I want. I don't know why, but it works.

    THANK YOU for putting me on the right path.

    Ken

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Although I can't imagine why you would want this, you could use

    SendKeys "+{TAB}"

Posting Permissions

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