Question : Tab control Select record on subform

On each page of a tab control I have a subform that, when a record is selected, values of hidden text boxes on the main form change. I use these text box values when opening a popup form from any page.

To keep the hidden text box values current, in the OnChange event of the tab control, I SetFocus to a control on the subform of the current page on the tab form. The code to update the hidden text boxes is fired from the OnEnter event of the control on the subform. This works great the first time a tab is selected. However, when a tab is revisited, focus is already set to the control on the subform so the text box values do not change.

Chances are good that the above explanation is not enough. Here's an example:
Tab 1 is selected. Focus is set to 1st record in it's subform. All hidden text boxes on the main form reflect the record selected on Tab 1.
Then Tab 2 is selected. Focus is set to a control on it's subform. Now the values of the hidden text boxes on the main form reflect the record selected on Tab 2.
Here's the problem, if you now go back and select Tab 1, the values in the hidden text boxes do not change. They still have values from Tab 2. At this time, the only way to update the hidden text boxes to reflect values on Tab 1 is to select another record in the subform on Tab 1.

Wow. I hope all of that makes sense. I guess I just need to know how to re-select a record on the subform when selecting a page on the tab form.

Thanks, Dale


Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
Private Sub Tab_Change()
If Me.TabNumber = 0 Then
Me.frmCounties.SetFocus
Me.frmCounties.Form.County.SetFocus
ElseIf Me.TabNumber = 1 Then
Me.frmPAM.SetFocus
Me.frmPAM.Form.PAM.SetFocus
ElseIf Me.TabNumber = 2 Then
Me.StatesStatesTab.SetFocus
ElseIf Me.TabNumber = 3 Then
Me.frmTerrAMs.SetFocus
Me.frmTerrAMs.Form.TerrAM.SetFocus
ElseIf Me.TabNumber = 4 Then
Me.frmTerrLFAs.SetFocus
Me.frmTerrLFAs.Form.TerrLFA.SetFocus
ElseIf Me.TabNumber = 5 Then
Me.frmTeamAMs.SetFocus
Me.frmTeamAMs.Form.TeamAM.SetFocus
ElseIf Me.TabNumber = 6 Then
Me.frmTeamLFAs.SetFocus
Me.frmTeamLFAs.Form.TeamLFA.SetFocus
ElseIf Me.TabNumber = 7 Then
Me.frmCRDs.SetFocus
Me.frmCRDs.Form.CRD.SetFocus
ElseIf Me.TabNumber = 8 Then
Me.frmZones.SetFocus
Me.frmZones.Form.Zone.SetFocus
ElseIf Me.TabNumber = 9 Then
Me.frmRegionAM.SetFocus
Me.frmRegionAM.Form.AM_REGION_REP_NAME.SetFocus
ElseIf Me.TabNumber = 10 Then
Me.frmRegionLFA.SetFocus
Me.frmRegionLFA.Form.LFA_REGION_REP_NAME.SetFocus
Else
End If
End Sub

Answer : Tab control Select record on subform

The enter event would be a poor choice for something critical to your app's operation ... you'd be much better off using the Current event of your form or subform to write these values. It's hard to determine exactly which is better, since it's not clear exactly when these hidden values should change.

Or, you could change how your app uses these "hidden" values, and instead look directly at the subform values instead of trying to fill fields on the main form.
Random Solutions  
 
programming4us programming4us