Display tab data depending on form criteria

T

Taz

I would like to know how to display one tab versus another depending on a
field on the form. I have an employee info form that has two tabs - one with
Pharmacists' training data, and one with the Technicians' training data.
There is also a field that designates the employee type - T for tech, and P
for Pharmacist. Is there a way to just display the Pharmacist training tab
when the employee type is a P, and display the Technician training tab when
the employee type is a T? TIA.
 
J

Jack Leach

You can set the visibility of the page to false. Probably you should also
explicitly select a page first to make sure you don't set the current page to
false. Pages are indexed starting at 0 so the first tab is 0, then 1 etc.:

If <somecondition> Then
Me.TabControl = 1
Me.TabControl.Pages(0).Visible = False
End If


hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

You'll want this on the AfterUpdate event of the control that you select the
employee type, and also in the Current event of the form (every time you move
to a new record). You might want to show neither if there is no "t" or "p"
in in the control (new record, null field). If your control is named
ctlEmpType, it might look something like this:


Private Sub ctlEmpType_AfterUpdate()
psSetTabs
End Sub

Private Sub Form_Current()
psSetTabs
End Sub

Private Sub SetTabs()
Dim sEmpType As String
sEmpType = Nz(Me.ctlEmpType, "")

If sEmpType = "T" Then
Me.TabControl.Pages(0).Visible = True
Me.TabControl = 0
Me.TabControl.Pages(1).Visible = False
Elseif sEmpType = "P" Then
Me.TabControl.Pages(1).Visible = True
Me.TabControl = 1
Me.TabControl.Pages(0).Visible = False
Else
Me.SomeOtherControl.SetFocus
Me.TabControl.Visible = False
End If
End Sub



hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
T

Taz

Jack Leach said:
You'll want this on the AfterUpdate event of the control that you select the
employee type, and also in the Current event of the form (every time you move
to a new record). You might want to show neither if there is no "t" or "p"
in in the control (new record, null field). If your control is named
ctlEmpType, it might look something like this:


Private Sub ctlEmpType_AfterUpdate()
psSetTabs
End Sub

Private Sub Form_Current()
psSetTabs
End Sub

Private Sub SetTabs()
Dim sEmpType As String
sEmpType = Nz(Me.ctlEmpType, "")

If sEmpType = "T" Then
Me.TabControl.Pages(0).Visible = True
Me.TabControl = 0
Me.TabControl.Pages(1).Visible = False
Elseif sEmpType = "P" Then
Me.TabControl.Pages(1).Visible = True
Me.TabControl = 1
Me.TabControl.Pages(0).Visible = False
Else
Me.SomeOtherControl.SetFocus
Me.TabControl.Visible = False
End If
End Sub



hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
T

Taz

That works great until I put this part of code in:

Else
Me.SomeOtherControl.SetFocus
Me.TabControl.Visible = False

After I put that in, it doesn't display at all.
 
J

Jack Leach

Yes, that was the intended purpose. I assumed if you're on a new record
(have not yet made a selection of T or P) you might not care to show any tabs
until that selection is made. After looking at it, to do this, you would
need to include Me.TabControl.Visible = True at the start of each of the
other two If statements (in case it was hidden from the last record).

Or if you like you can leave this out and the state of the tab visiblility
will be whatever it last was until the user makes a selection from ctlEmpType.

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top