If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Tab Controls
When using a tab control on a form, is it possible to change which
page displays when a combo box selection is made? Also, if this is possible, how would I make it so that tab's page displays when navigating through the records based on the prior combo box selection? |
#2
|
|||
|
|||
Tab Controls
To select the tabbed page based on the combobox selection:
Private Sub YourComboName_AfterUpdate() Select Case YourComboName Case "PageOne" Me.YourTabControl = 0 Case "PageTwo" Me.YourTabControl = 1 Case "PageThree" Me.YourTabControl = 2 Case Else Me.YourTabControl = 0 End Select End Sub Notice that the Tabbed Page index is Zero-based. The first page's value is 0, the second is 1, etc. To have this page dispaly persist when moving from record to record, the combobox needs to be bound to a field in the underlying table/query, then add this code: Private Sub Form_Current() Select Case YourComboName Case "PageOne" Me.YourTabControl = 0 Case "PageTwo" Me.YourTabControl = 1 Case "PageThree" Me.YourTabControl = 2 Case Else Me.YourTabControl = 0 End Select End Sub -- There's ALWAYS more than one way to skin a cat! Answers/posts based on Access 2000/2003 Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...forms/200901/1 |
#3
|
|||
|
|||
Tab Controls
It's simpler to just call the AfterUpdate event of the combo box from the
Current event: Private Sub Form_Current() Call yourComboName_AfterUpdate End sub -- HTH Dale email address is invalid Please reply to newsgroup only. "Linq Adams via AccessMonster.com" wrote: To select the tabbed page based on the combobox selection: Private Sub YourComboName_AfterUpdate() Select Case YourComboName Case "PageOne" Me.YourTabControl = 0 Case "PageTwo" Me.YourTabControl = 1 Case "PageThree" Me.YourTabControl = 2 Case Else Me.YourTabControl = 0 End Select End Sub Notice that the Tabbed Page index is Zero-based. The first page's value is 0, the second is 1, etc. To have this page dispaly persist when moving from record to record, the combobox needs to be bound to a field in the underlying table/query, then add this code: Private Sub Form_Current() Select Case YourComboName Case "PageOne" Me.YourTabControl = 0 Case "PageTwo" Me.YourTabControl = 1 Case "PageThree" Me.YourTabControl = 2 Case Else Me.YourTabControl = 0 End Select End Sub -- There's ALWAYS more than one way to skin a cat! Answers/posts based on Access 2000/2003 Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...forms/200901/1 |
#4
|
|||
|
|||
Tab Controls
"Linq Adams via AccessMonster.com" u28780@uwe wrote in
news:8fd518e122524@uwe: To select the tabbed page based on the combobox selection: Private Sub YourComboName_AfterUpdate() Select Case YourComboName Case "PageOne" Me.YourTabControl = 0 Case "PageTwo" Me.YourTabControl = 1 Case "PageThree" Me.YourTabControl = 2 Case Else Me.YourTabControl = 0 End Select End Sub Notice that the Tabbed Page index is Zero-based. The first page's value is 0, the second is 1, etc. I have recently run into a situation where I had to add pages to a tab and the logical order of the pages changed the page indexes. Because of that, I'm moving away from using indexes for working with tabs. For instance, in the OnChange event of the tab control, I use: Select Case Me!ctlTab.Pages(Me!ctlTab).Name Case "PageOne" ... Case "PageTwo" ... End Select and so forth. Unfortunately, I can't figure out a way to set the value of the tab based on the name. The only thing I can think of is a Byzantine routine that walks through the Pages collection and checks the name, and then returns the value. Public Function GetTabValueFromPageName(ctl As Control, _ strPageName As String) As Integer ' returns -1 if strPageName does not exist ' otherwise returns value for strPageName Dim i As Integer Dim intReturn As Integer intReturn = -1 For i = 0 To ctl.Pages.Count - 1 If ctl.Pages(i).Name = strPageName Then intReturn = i Exit For End If Next i GetTabValueFromPageName = intReturn End Function Am I just missing something that would be much easier? In any case, with the function above, and if your listbox returns the name of the tab page, then you could replace the original code quoted at the top with this: Private Sub YourComboName_AfterUpdate() Me!YourTabControl = GetTabValueFromPageName (Me!YourTabControl, _ Me!YourComboName) End Sub I'd be delighted to hear that there's an easier way and that I'm just being obtuse. -- David W. Fenton http://www.dfenton.com/ usenet at dfenton dot com http://www.dfenton.com/DFA/ |
#5
|
|||
|
|||
Tab Controls
=?Utf-8?B?RGFsZSBGeWU=?= wrote in
: It's simpler to just call the AfterUpdate event of the combo box from the Current event: Private Sub Form_Current() Call yourComboName_AfterUpdate End sub Meh. I find that it's often unreliable attempting to do that, so if I need to call the same code in more than one event, I'll write a private subroutine that both events can call. Seems much cleaner to me. -- David W. Fenton http://www.dfenton.com/ usenet at dfenton dot com http://www.dfenton.com/DFA/ |
#6
|
|||
|
|||
Tab Controls
David,
I had the same problem, but am using the tabs caption, instead of the name. Dale "David W. Fenton" wrote in message 36.98... "Linq Adams via AccessMonster.com" u28780@uwe wrote in news:8fd518e122524@uwe: To select the tabbed page based on the combobox selection: Private Sub YourComboName_AfterUpdate() Select Case YourComboName Case "PageOne" Me.YourTabControl = 0 Case "PageTwo" Me.YourTabControl = 1 Case "PageThree" Me.YourTabControl = 2 Case Else Me.YourTabControl = 0 End Select End Sub Notice that the Tabbed Page index is Zero-based. The first page's value is 0, the second is 1, etc. I have recently run into a situation where I had to add pages to a tab and the logical order of the pages changed the page indexes. Because of that, I'm moving away from using indexes for working with tabs. For instance, in the OnChange event of the tab control, I use: Select Case Me!ctlTab.Pages(Me!ctlTab).Name Case "PageOne" ... Case "PageTwo" ... End Select and so forth. Unfortunately, I can't figure out a way to set the value of the tab based on the name. The only thing I can think of is a Byzantine routine that walks through the Pages collection and checks the name, and then returns the value. Public Function GetTabValueFromPageName(ctl As Control, _ strPageName As String) As Integer ' returns -1 if strPageName does not exist ' otherwise returns value for strPageName Dim i As Integer Dim intReturn As Integer intReturn = -1 For i = 0 To ctl.Pages.Count - 1 If ctl.Pages(i).Name = strPageName Then intReturn = i Exit For End If Next i GetTabValueFromPageName = intReturn End Function Am I just missing something that would be much easier? In any case, with the function above, and if your listbox returns the name of the tab page, then you could replace the original code quoted at the top with this: Private Sub YourComboName_AfterUpdate() Me!YourTabControl = GetTabValueFromPageName (Me!YourTabControl, _ Me!YourComboName) End Sub I'd be delighted to hear that there's an easier way and that I'm just being obtuse. -- David W. Fenton http://www.dfenton.com/ usenet at dfenton dot com http://www.dfenton.com/DFA/ |
#7
|
|||
|
|||
Tab Controls
David,
Any particular circumstances where you have had problems with this? I cannot recall ever having a problem doing it this way. Although I agree that your way is probably cleaner. -- HTH Dale email address is invalid Please reply to newsgroup only. "David W. Fenton" wrote: =?Utf-8?B?RGFsZSBGeWU=?= wrote in : It's simpler to just call the AfterUpdate event of the combo box from the Current event: Private Sub Form_Current() Call yourComboName_AfterUpdate End sub Meh. I find that it's often unreliable attempting to do that, so if I need to call the same code in more than one event, I'll write a private subroutine that both events can call. Seems much cleaner to me. -- David W. Fenton http://www.dfenton.com/ usenet at dfenton dot com http://www.dfenton.com/DFA/ |
#8
|
|||
|
|||
Tab Controls
=?Utf-8?B?RGFsZSBGeWU=?= wrote in
: Any particular circumstances where you have had problems with this? I cannot recall ever having a problem doing it this way. Although I agree that your way is probably cleaner. I can't recall the exact circumstances, since it was so long ago that I started avoiding doing it! The problem was the for whatever reason, the code compiled but at runtime, couldn't find to sub. Or maybe it was the other way around, that it threw a compile error but worked? Also, as I seem to recall, the problem seemed to usually happen if I was referring to an event in a subform or parent from from the other parent or child (respectively). Using the PUBLIC keyword didn't always resolve it. But I honestly can't remember the specifics. It was confusing to me and I couldn't figure out the pattern, so I coded around it in a way that, in my opinion, was cleaner in the long run. -- David W. Fenton http://www.dfenton.com/ usenet at dfenton dot com http://www.dfenton.com/DFA/ |
Thread Tools | |
Display Modes | |
|
|