Tab Control Focus

S

scott

I have a tab control and a subform on the 3rd tab. Is there anyway to detect
if a user clicks a certain tab?

My problem is when user clicks 3rd tab, I need the current record to go to a
new record on the subform. I've tried putting an invisible rectangle over
the tab, but nothing seems to allow this capability?
 
G

Guest

Hi Scott,

You can use the "On Change" event of the tab control to detect a change in
the active tab. Then, you can process your code based on which tab is
selected.

Note that to get to this event you need to select the main outer control,
not one of the individual tabs. You may want to give your tabs meaningful
names prior to writing your code (if you haven't already).

Listed below is some sample code that I had written to dynamically load a
subform depending on which tab was selected. This was done to increase the
speed of the initial opening of the form. This is different than what you
want to do, but I think it will give you some ideas as far as how to work
with tabs (watch the line wrapping).

Private Sub TabCtlMaster_Change()

Dim strErrorMsg As String
Dim strTabCntrlSource As String
Dim strLinkMaster As String
Dim strLinkChild As String
Dim subfrm As Access.SubForm


On Error GoTo ErrorHandler

Select Case Me.TabCtlMaster.Pages(Me.TabCtlMaster).Name

Case "tabAcctgFAData"
Set subfrm = Me.subformFA2002
strTabCntrlSource = "fz tzimpFAExport Subform"
strLinkMaster = "WO NO"
strLinkChild = "Work Order"

Case "tabWCIP"
Set subfrm = Me.subformWCIP
strTabCntrlSource = "fz WCIP Info by WO Subform"
strLinkMaster = "WO NO"
strLinkChild = "Work Order"

Case "tabUPRS"
Set subfrm = Me.subformUPRS
strTabCntrlSource = "fz tzimpUPRSMaster Subform"
strLinkMaster = "WO NO"
strLinkChild = "WorkOrderNumber"

Case "tabEmerg"
Set subfrm = Me.subformEmergency
strTabCntrlSource = "fz tzimpEmergencyInfo Subform"
strLinkMaster = "WO NO"
strLinkChild = "WO#"

Case Else
Exit Sub

End Select

With subfrm
If Nz(.SourceObject, "") = "" Then
.SourceObject = strTabCntrlSource
.LinkMasterFields = strLinkMaster
.LinkChildFields = strLinkChild
End If
End With

ExitLine:
Set subfrm = Nothing
Exit Sub

ErrorHandler:
strErrorMsg = "An error was encountered while attempting to assign the
subform for this page. "
strErrorMsg = strErrorMsg & "Please write down the following error
information and give it to "
strErrorMsg = strErrorMsg & "your database administrator:" & vbCrLf & vbCrLf
strErrorMsg = strErrorMsg & Err.Number & " - " & Err.Description
MsgBox strErrorMsg
Resume ExitLine

End Sub

HTH, Ted Allen
 
S

scott

thx. that works great.


Ted Allen said:
Hi Scott,

You can use the "On Change" event of the tab control to detect a change in
the active tab. Then, you can process your code based on which tab is
selected.

Note that to get to this event you need to select the main outer control,
not one of the individual tabs. You may want to give your tabs meaningful
names prior to writing your code (if you haven't already).

Listed below is some sample code that I had written to dynamically load a
subform depending on which tab was selected. This was done to increase
the
speed of the initial opening of the form. This is different than what you
want to do, but I think it will give you some ideas as far as how to work
with tabs (watch the line wrapping).

Private Sub TabCtlMaster_Change()

Dim strErrorMsg As String
Dim strTabCntrlSource As String
Dim strLinkMaster As String
Dim strLinkChild As String
Dim subfrm As Access.SubForm


On Error GoTo ErrorHandler

Select Case Me.TabCtlMaster.Pages(Me.TabCtlMaster).Name

Case "tabAcctgFAData"
Set subfrm = Me.subformFA2002
strTabCntrlSource = "fz tzimpFAExport Subform"
strLinkMaster = "WO NO"
strLinkChild = "Work Order"

Case "tabWCIP"
Set subfrm = Me.subformWCIP
strTabCntrlSource = "fz WCIP Info by WO Subform"
strLinkMaster = "WO NO"
strLinkChild = "Work Order"

Case "tabUPRS"
Set subfrm = Me.subformUPRS
strTabCntrlSource = "fz tzimpUPRSMaster Subform"
strLinkMaster = "WO NO"
strLinkChild = "WorkOrderNumber"

Case "tabEmerg"
Set subfrm = Me.subformEmergency
strTabCntrlSource = "fz tzimpEmergencyInfo Subform"
strLinkMaster = "WO NO"
strLinkChild = "WO#"

Case Else
Exit Sub

End Select

With subfrm
If Nz(.SourceObject, "") = "" Then
.SourceObject = strTabCntrlSource
.LinkMasterFields = strLinkMaster
.LinkChildFields = strLinkChild
End If
End With

ExitLine:
Set subfrm = Nothing
Exit Sub

ErrorHandler:
strErrorMsg = "An error was encountered while attempting to assign the
subform for this page. "
strErrorMsg = strErrorMsg & "Please write down the following error
information and give it to "
strErrorMsg = strErrorMsg & "your database administrator:" & vbCrLf &
vbCrLf
strErrorMsg = strErrorMsg & Err.Number & " - " & Err.Description
MsgBox strErrorMsg
Resume ExitLine

End Sub

HTH, Ted Allen
 

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