Are there option groups, combo boxes, textboxes that are on the form
but not on a tab page? If no, just loop through the form's controls
and ignore the tab control:
For Each ctl In Me![PageC3]
Select ctl.ControlType
Case acOptionGroup, acComboBox, acTextBox
ctl.Value = ctl.DefaultValue
End Select
Next ctl
Note that you do not need to set focus to a control to change its
value -- just use the Value property, not the Text.
If yes, I assume that you don't want to affect the controls that are
not on a tab page. So then what you can do is test if the control
has a Parent of a Parent; if it does, then you can test the Name of
that Parent and see if it's the name of the tab control. You'll
need to trap for the error that will occur if the control doesn't
have a Parent.Parent property:
Dim strParentName As String
On Error Resume Next
For Each ctl In Me.Controls
Select ctl.ControlType
Case acOptionGroup, acComboBox, acTextBox
strParentName = ctl.Parent.Parent.Name
If Err.Number = 0 Then
If strParentName = "NameOfTabControl"
Then _ ctl.Value = ctl.DefaultValue
ElseIf Err.Number = 2452 Then
' control is on main form
Err.Clear
Else
' some other error has occurred
MsgBox "Error"
Err.Clear
End If
End Select
Next ctl
--
Ken Snell
<MS ACCESS MVP>
Li Qiu said:
Need to reset controls(CB,TB,OptionGroup) in several of the pages
in the multi-tab form as pseudo code below. But each page in the
multi-tab is not collection. Can someone help me to get arround the
problem. Thanks.
ClearText()
For Each ctl In Me![PageC3]
If <controltype is acOptionGroup, acComboBox, acTextBox>
Then ctl.SetFocus
ctl.Text = ctl.DefaultValue
End If
Next
Do the same thing for other pages