Solved

Event On Tab Click

Posted on 2006-07-05
7
299 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
ID: 17043332
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
ID: 17043378
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
ID: 17046365
<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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 1

Author Comment

by:H-SC
ID: 17046390
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
ID: 17046401
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
ID: 17046483
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
ID: 17047030
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

777 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