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