Bob Gajewski
rbgajewski at roadrunner.com
Sat Jan 3 13:54:40 CST 2009
Hi Folks
I have an event database, and I am having trouble with referencing controls
on a subform.
Using a command button (cmdShowTier1) on the main form (frmEvents), I want
to change the border color on selected textboxes on the subform
(sfrmEventSectionLeft). Each field (EventSeatA001 through EventSeatR023) in
the subform has a TAG property set to "Tier1", "Tier2" or "Tier3". Below is
the code. The commented-out MsgBox lines were for trouble-shooting only.
CODE SAMPLE
============================================================================
=================
Function ShowTier3()
Dim ctl As Control
Forms![frmEvents]![sfrmEventSectionLeft].SetFocus
Forms![frmEvents]![sfrmEventSectionLeft].Form![EventSeatA001].SetFocus
For Each ctl In Me.Controls
'MsgBox "The focus is on " & ctl.Name
If ctl.ControlType = acTextBox Then
If ctl.Tag = "Tier3" Then
ctl.BorderColor = vbBlue
End If
End If
Next ctl
Forms![frmEvents].SetFocus
End Function
Function HideTier3()
Dim ctl As Control
Forms![frmEvents]![sfrmEventSectionLeft].SetFocus
Forms![frmEvents]![sfrmEventSectionLeft].Form![EventSeatA001].SetFocus
For Each ctl In Me.Controls
'MsgBox "The focus is on " & ctl.Name
If ctl.ControlType = acTextBox Then
If ctl.Tag = "Tier3" Then
ctl.BorderColor = vbBlack
End If
End If
Next ctl
Forms![frmEvents].SetFocus
End Function
Private Sub cmdShowTier3_Click()
On Error GoTo Err_cmdShowTier3_Click
cmdHideTier3.Visible = True
cmdHideTier3.SetFocus
cmdShowTier3.Visible = False
ShowTier3
'MsgBox "Tier 3 seats should now be blue", vbOKOnly
Exit_cmdShowTier3_Click:
Exit Sub
Err_cmdShowTier3_Click:
MsgBox Err.Description
Resume Exit_cmdShowTier3_Click
End Sub
Private Sub cmdHideTier3_Click()
On Error GoTo Err_cmdHideTier3_Click
cmdShowTier3.Visible = True
cmdShowTier3.SetFocus
cmdHideTier3.Visible = False
HideTier3
'MsgBox "Tier 3 seats should now be black", vbOKOnly
Exit_cmdHideTier3_Click:
Exit Sub
Err_cmdHideTier3_Click:
MsgBox Err.Description
Resume Exit_cmdHideTier3_Click
End Sub
============================================================================
=================
The code moves the focus to the subform, but the Me.Controls just cycles
through the main form.
How do I reference the subform, so that the proper fields are updated?
I really appreciate any help or suggestions.
Thanks,
Bob Gajewski