Bob Gajewski
rbgajewski at roadrunner.com
Sat Jan 3 14:02:52 CST 2009
It figures - I've been working on this for hours, but as soon as I post the question I figure out the answer! I just had to replace "For Each ctl In Me.Controls" with "For Each ctl In [sfrmEventSectionLeft].Controls". But thanks to everyone who was ready to help!! Bob -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Bob Gajewski Sent: Saturday, January 03, 2009 14:55 PM To: 'Access Developers discussion and problem solving' Subject: [AccessD] Need help with controls on a subform 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 -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com