Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Toronto, Ontario, Canada
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Tab Control (2002)

    I have a form in a database, and I would like to run a macro when the end user switches from 'tab1" to "tab2". When I try to create this event, the macro doesnt run when I switch tabs. It only runs when I click on the tab2 form area. Is what I'm trying to accomplish possible?
    Tab2 doesnt have a "show" event which I could toss my macro code into, does it? I even tried creating buttons that would switch tabs and run the macro, and placing them overtop of the tab selection, but the button automatically goes behind the tab form. Any ideas?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Tab Control (2002)

    What you need is the Change event of the tab control. That's the only one that actually fires when a user clicks on one of the tabs.
    Charlotte

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Tab Control (2002)

    You must use the On Change event of the tab control as a whole, not of the individual tab pages. You can select the tab control by clicking immediately to the right of the rightmost tab. You can now create an event procedure for the On Change event. The Value of the tab control is the zero-based index of the tab page clicked by the user, so the first tab page is 0, the second one is 1 etc.

    Private Sub MyTabCtl_Change()
    Select Case MyTabCtl.Value
    Case 0 ' first tab clicked
    ' code to execute if first tab clicked
    Case 1 ' second tab clicked
    ' code to execute if second tab clicked
    ...
    End Select
    End Sub

  4. #4
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Toronto, Ontario, Canada
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Tab Control (2002)

    Thanks Hans, works perfectly!

  5. #5
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Toronto, Ontario, Canada
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Tab Control (2002)

    Sorry, one more quick question related to all this.
    What command do I used to run a macro?
    Case 1
    DoCmd.RunMacro mcroTest1
    End Select

    Is that it?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Tab Control (2002)

    The name of the macro is a string argument, so it must be in quotes:

    DoCmd.RunMacro "mcroTest1"

Posting Permissions

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