Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Apr 2005
    Posts
    61

    Unanswered: How do you change tab in tab control using VBA?

    Hello to All,

    I was just wondering as to how I could change the tab on a tab conrol using vba. Say I have a button that selects a record when i click the button I want to change from Tab1 to Tab2 in my tab contrl. if anyone knows how I thank you in advance.

    Mythos

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    What an interesting question - I am going to find out how! And not only because your handle is my favourite Greek beer (mmmmmm...... Mythos).

    This is when you yearn for an Access Macro recorder.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Code:
    Me.TabControlName.Pages.Item(PageIndexNumber).SetFocus
    or
    Code:
    Me.TabControlName.Pages.Item("PageName").SetFocus
    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Tab Control

    You can also re-order the tab controls:

    Me.Controls("GrantPage").Pages("Mentors").Visible = True
    Me.Controls("GrantPage").Pages("Mentors").PageInde x = 0

    I had a case where depending on which grant was selected, they wanted certain tabs on the tab control to show and in a certain order.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Mar 2008
    Posts
    23
    How about in addition to rearranging tabs you want to be able to insert new ones and remove old ones on the fly with VBA code. The help screens say that you can only add tabs in design mode. Does that mean this can't be done?

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Probably! You could add tabs in design mode and hide and unhide them in VBA though, which is what I do.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  7. #7
    Join Date
    Mar 2008
    Posts
    23
    Thanks!! Sorry for the posting this question twice. But when I posted to this thread I didn't see it show up in the new threads section of the message board. So I figured it was too old and no one would see it.

  8. #8
    Join Date
    Mar 2008
    Posts
    23
    Quote Originally Posted by StarTrekker
    Probably! You could add tabs in design mode and hide and unhide them in VBA though, which is what I do.
    How do you do this? I'm having trouble figuring out how to iterate through the pages collection for the tab control. I want to be able to unhide tabs and rename them using a list of names from a query.

  9. #9
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Name each of your tabs with names like TabPage1, TabPage2, TabPage3 etc. Then you can refer to each page directly, using a For loop. Use the Caption property to change the title (or caption) of each tab for the user.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  10. #10
    Join Date
    Mar 2008
    Posts
    23
    Thanks!! That will work just fine. It's a little weird there's no way to directly access the page index for the pages collection though.

  11. #11
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I'm not certain you can't. I don't do a lot of hiding of page tabs

    Looking at post 3, you probably can.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  12. #12
    Join Date
    Mar 2008
    Posts
    23
    Quote Originally Posted by StarTrekker
    Name each of your tabs with names like TabPage1, TabPage2, TabPage3 etc. Then you can refer to each page directly, using a For loop. Use the Caption property to change the title (or caption) of each tab for the user.
    Could I see your code for doing this? I'm not sure how to put together something like "TabPage" & i that will go in...
    Pages.Item("name")

    Can you do something like Pages.Item(strVariable) ?

  13. #13
    Join Date
    Mar 2008
    Posts
    23
    --- delete ---

  14. #14
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I was meaning to reference the page tab control directly... eg

    Me.Controls("tabPage" & i).Visible = True

    That kind of thing.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  15. #15
    Join Date
    Mar 2008
    Posts
    23
    ohhhh, ok. There's so many ways to refer to things I miss the simplest ones sometimes. Plus not sure I would've thought of concatenating the name parameter like that. Cool! Thanks!

Posting Permissions

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