Tab Sheets on Form

S

SITCFanTN

I have a form that has a combo box field with about 15 selections. Also on
the form I have a tab control with 15 sheets titled with the same names that
are in my combo box. What I 'd like to do is code that would open the
specific tab control sheet after the combo box is selected.

so if "Black" is selected in the Combo Box, the tab control sheet titled,
"Black" would display. Then if "Green" was selected in the combo box, after
update, I'd like the tab control sheet named "Green" would display.

Any ideas how or even if this can be accomplished. Thanks for your help.
Happy holidays to you and yours.
 
J

John Spencer

Try code like the following

Private Sub cboxSetPage_AfterUpdate()
Dim i As Long
If Len(Me.cboxSetPage & "") > 0 Then
For i = 0 To Me.TabCtLPages.Pages.Count - 1
If Me.cboxSetPage = Me.TabCtLPages.Pages(i).Name _
Or Me.cboxSetPage = Me.TabCtLPages.Pages(i).Caption Then
Me.TabCtLPages = i
Exit For
End If
Next i
End If
End Sub

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
S

SITCFanTN

So John, this will work for all my tabs, I don't need to call out each one
by name?

Thanks so much!
 
D

Dale Fye

This may be a silly question, but why would you need to do this? It already
only takes a single click to move to a tab control, why would you need to
dropdown a combo box, scroll through the 15 possible values, and then click
the one you want, when you could just click on the appropriate tab?

At any rate, an even quicker way would be to add a numeric value (hidden) to
the combo box (give it two columns and make the hidden numeric column the
bound column). So the values for your combo might look like (0, "Black", 1,
"White", 2, "Green", ...).

Then, in the combo boxes AfterUpdate event, just set the tab controls value
to the value of the combo box.

Private Sub cbo_WhichTab_AfterUpdate

me.cbo_WhichTab = NZ(me.cbo_WhichTab, 0)

END SUB

HTH
Dale
 
S

SITCFanTN

Hi Dale,

I didn't think of that, removing the combo box. I will need to code the
AfterUpdate event for each tab then right. I'm pretty new to VBA so if Tab1
needed to be updated to table titled "tblCase", can you help me wiht the code
for one tab, then I'd be able to do the other 14.

thanks so much, this is a great help.
 
D

Dale Fye

Not quite sure what you mean?

The tab control has a Change event that you can use to test which page you
are on and perform certain operations. You would use the tab controls
"Value" property to identify the index of the page that is selected and do
whatever you want. As an example:

Private Sub tab_MyTab_Change

msgbox "Tab index = " & me.tab_MyTab & vbcrlf _
& "Tab title:'" & me.tab_MyTab.Page(me.tab_MyTab).name & "'"

End sub

HTH
Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

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