Tabs not cooperating (1 Viewer)

jmenken

New member
Local time
Today, 07:03
Joined
Oct 10, 2015
Messages
4
Creating a database in Access 2010. I have a form with 5 tabs, each tab/page has multiple subforms. However, when I click on a tab (any of them), it does not open at the top of the tab/page. It scrolls down to the control last clicked on the previous record

For Example, the Operations tab has 3 subforms. The subforms are long enough that the user has to scroll down to get to the 3rd subform. Below the 3rd subform is a command button that executes code to spell check memo fields on each subform.

Here's the issue...when I click the Operations tab, it always opens at the bottom of the page with the focus on the command button... I'm assuming because that was the last thing clicked on the previous record.

I've tried going to the tabs On Click event and setting the focus on the first control on the first subform, but it doesn't seem to make a difference.

I've hit a wall and can't figure out how to fix this issue.
 

MarkK

bit cruncher
Local time
Today, 05:03
Joined
Mar 17, 2004
Messages
8,186
I've tried going to the tabs On Click event and setting the focus on the first control on the first subform, but it doesn't seem to make a difference.
Try using the Tab_Change() event. The change event fires when you change tabs. Then determine the current tab, and then set focus appropriately.
 

jmenken

New member
Local time
Today, 07:03
Joined
Oct 10, 2015
Messages
4
Try using the Tab_Change() event. The change event fires when you change tabs. Then determine the current tab, and then set focus appropriately.

Unfortunately, that didn't work. :banghead:
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:03
Joined
May 7, 2009
Messages
19,246
ofcourse it will work. Tab_Change() is just an example, you should replace the "Tab" word there with the correct name of your tab control.

Private Sub yourTabControl_Change()
' which tab number you wish to inspect, tab number are 0 based. meaning the first tab=0
if yourTabControl.Value = 0 Then
' set focus to your subform
End if
 

jmenken

New member
Local time
Today, 07:03
Joined
Oct 10, 2015
Messages
4
ofcourse it will work. Tab_Change() is just an example, you should replace the "Tab" word there with the correct name of your tab control.

Private Sub yourTabControl_Change()
' which tab number you wish to inspect, tab number are 0 based. meaning the first tab=0
if yourTabControl.Value = 0 Then
' set focus to your subform
End if

hmmm...where is an example of what I have.
'Inventory' is the tab name
'sbfrmInspStorage' is the subform name
trying to set focus on 'InspStorageTempYes' check box

Private Sub Inventory_Change()
sbfrmInspStorage.SetFocus
sbfrmInspStorage.Form!InspStorageTempYes.SetFocus
End Sub

If I have something incorrect, can you please rewrite it the correct way, so I can see it. and then transfer it to the other tabs?

This my first time working with tabs, so I appreciate the help!
 

MarkK

bit cruncher
Local time
Today, 05:03
Joined
Mar 17, 2004
Messages
8,186
You need to handle the Change event of the Tab control. The Page doesn't even raise a Change event. To see what events are available for a control, right click the control in design view and select Properties from the popup menu. This opens the property sheet for the control. Click the Event tab.

There is a list of events for the control. To handle an event in code, select "[Event Procedure]" from the combo-box next to the event you want to handle, and then in the very far right click the button with the three dots, and the signature to handle the event is automatically inserted in the associated code module.
Hope this helps,
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:03
Joined
May 7, 2009
Messages
19,246
this is your controltab.
 

Attachments

  • Capture_2015_10_11_11_07_00_917.png
    Capture_2015_10_11_11_07_00_917.png
    33.5 KB · Views: 184
Last edited:

jmenken

New member
Local time
Today, 07:03
Joined
Oct 10, 2015
Messages
4
Ahhhh...now I get it. Classic example of not being able to see the forest (TabControl) for the trees (pages). :banghead:

I found this code in another post(link below) that help me get what I need.Here's the code, with my edit...
Private Sub YourTabbedControl_Change()
If Me.YourTabbedControl.Value = 0 Then
SubForm1.SetFocus
SubForm1.Form!Field1.SetFocus
ElseIf Me.YourTabbedControl.Value = 1
SubForm2.SetFocus
SubForm2.Form!Field1.SetFocus
ElseIf Me.YourTabbedControl.Value = 2 Then
SubForm3.SetFocus
SubForm3.Form!Field1.SetFocus
End If
End Sub

.access-programmers.co.uk/forums/showthread.php?t=164828
*my post count won't allow me to insert a hyperlink

Thank you everyone for walking me through this.
 

MarkK

bit cruncher
Local time
Today, 05:03
Joined
Mar 17, 2004
Messages
8,186
Pro Tip: If you ever find you want to re-arrange the pages, and this breaks your select case (or If Else) block, is create a property that returns the current page . . .
Code:
Property Get ActivePage as Access.Page
   With Me.[I]MyTabControl[/I]
      Set ActivePage = .Pages(.Value)
   End With
End Property
. . . so now you can write a handler that's based on the page names, which don't change if you change their order . . .
Code:
Private Sub [I]MyTabControl[/I]_Change()
   Select Case Me.ActivePage.Name
      Case "pgCustomer"
         sfmCustomer.SetFocus
      Case "pgOrder"
         sfmOrder.SetFocus
[COLOR="Green"]      ' . . . [/COLOR]
End Sub
 

Users who are viewing this thread

Top Bottom