Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear controls on a specific tab on a form? 1

Status
Not open for further replies.

glgcag

MIS
Apr 25, 2001
160
US
I have a form with 6 tabs. On 2 of the 6 tabs I need to clear the data and refresh it on "after_update" of a combo box. Since I'm using unbound controls, I can use the "clearing" code in the following module, but it will clear all tabs, not just the two I need to clear. Is there a way to reference just the controls on the two tabs? (Keep in mind, I'm not using subforms on the tabs, otherwise this problem would go away.)

Code:
For Each ctl In MyForm.Controls
        If (ctl.ControlType = acTextBox) Then
            ctl.Value = Null
        End If
        And so on for other control types . . .
Next ctl
 
How about and looking at the Parent? The name should be "Page2", or such like.
 
I've tried referencing it like this:

Forms!fRMProjects!pgBAInformation.control

Is that what you mean?
 
Hi!

Use the Tag property of the controls. In the Tag property put Tab1 or Tab2 etc depending on where it resides the alter you code to check for it:

For Each ctl In MyForm.Controls
If (ctl.ControlType = acTextBox) And ctl.Tag = "Page2" Then
ctl.Value = Null
End If
And so on for other control types . . .
Next ctl

Even though the controls are on a tab Access considers them to be on the main form.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Except the whole purpose of running a module that clears the controls on the tabs is not have to manually code in a "clear" for each control. If I have to set a tag for each control, it's the same thing, in which case I might as well just clear the controls on each tab via code on the form, right?
 
No, I mean
If Me.txtText.Parent="Page2" Then..
 
Hi!

Well you got curious and I looked into it. There is a way:

For Each ctl In Me.Page1.Controls
If (ctl.ControlType = acTextBox) Then
ctl.Value = Null
End If
And so on for other control types . . .
Next ctl

this will only look at the controls on Page1

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
It worked brilliantly! Thank you very much!

Here's how I implemented it (for those that are interested):

In the code of after_update of my combo box I put
Code:
If ClearControls(Forms!fRMProjects.pgBAInformation) = false
     'Raise err
End if
Here's the function code:
Code:
Public Function ClearControls(ByVal ctlSource As Control) As Boolean
On Error GoTo ErrHere
    Dim ctl As Control
    
    For Each ctl In ctlSource.Controls
        If (ctl.ControlType = acTextBox) Then
            ctl.Value = ""
        End If
    Next ctl
    ClearControls = True
    
ExitHere:
    Exit Function
ErrHere:
    ClearControls = False
    Resume ExitHere
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top