Solved

Event On Tab Click

Posted on 2006-07-05
7
278 Views
Last Modified: 2008-03-06
I have a form that has a tab control on it that has four tabs.  One of the tabs has a subform on it and one field.  I would like for the following to occur when the user clicks on the 4th tab.

If the one field on the tab is not null then the subform should not be visible else the subform should be visible.  This works on non-tabed forms using the on current but I cant seem to get this to work on a form with tab ctl using the on tab click.
0
Comment
Question by:H-SC
  • 4
  • 2
7 Comments
 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 125 total points
Comment Utility
Try this:

Private Sub TabCtl1_Change()
On Error GoTo Error_Routine

'commits any changes
If Me.Dirty Then Me.Dirty = False
Select Case Me.TabCtl1.Value
    Case Is = 0   'run code for page1...(Me.Page1.PageIndex = 0)
        .............................................
        TabCtl1.Pages.Item(0).SetFocus
    Case Is = 1   'run code for page2......(Me.Page2.PageIndex = 1)
        .............................................
        TabCtl1.Pages.Item(1).SetFocus
    Case Is = 2   'run code for page3.....(Me.Page3.PageIndex = 2)
        .............................................
        TabCtl1.Pages.Item(2).SetFocus
    Case Is = 3   'run code for page4.....(Me.Page4.PageIndex = 3)
        If Not IsNull([yourField]) then
           Me!Subform4.Visible = False
        Else
           Me!Subform4.Visible = True
        End If
        TabCtl1.Pages.Item(3).SetFocus
End Select
Exit_Continue:
        Exit Sub
Error_Routine:
        MsgBox "Error# " & Err.Number & " " & Err.Description
        Resume Exit_Continue

End Sub
0
 
LVL 38

Expert Comment

by:puppydogbuddy
Comment Utility
PS: You have to replace the subform/field names I used with your own.  Also the dotted lines indicate optional code that you may want to add.
0
 
LVL 44

Expert Comment

by:GRayL
Comment Utility
<One of the tabs has a subform on it and one field>  Do you mean the 4th tab has a subform and a control?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:H-SC
Comment Utility
GRayL,

Yes, only the fourth tab has everything that my question involves.  When the user clicks on that 4th tab then the event occurs (only on the items that pertain to that tab and that screen).

0
 
LVL 1

Author Comment

by:H-SC
Comment Utility
puppydogbuddy,

I will try...I think that I would only need one section of your code...I would only want to apply this event on one tab/field
0
 
LVL 38

Expert Comment

by:puppydogbuddy
Comment Utility
You definitely want the If Me.Dirty .....as the first line of your code in the tab control........it centrallly commits (saves) all changes that have occured on any of the individual tabs, reducing the code that has to be written for the individual tabs.  Also, if you only use case 4, be sure you have a case else so that you will be protected from the possibility of "fall thru" code.

                                        PDB  
0
 
LVL 38

Expert Comment

by:puppydogbuddy
Comment Utility
oops! typo....the prior comment above should have referred to case 3 (for the 4th tab) not case 4.  Tab page indexes start with 0.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now