Function to generalized Function

timothyl

Registered User.
Local time
Today, 03:13
Joined
Jun 4, 2009
Messages
92
Hello, I am tring to code my first generalized function, I have(which works as a function on a form)

Function ClearAll(c As String)
Dim ctl As Control
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acCheckBox
If ctl.ControlSource = "" And ctl.Tag <> c Then
ctl.Value = Null
End If
Case Else
End Select
Next ctl
End If

Want to place in a module to create a general function so can use on all forms.

Have placed in a module, but not working, dose not like the
Me.Controls
which I can see that it would not as it is know in a module not on a spiecific form. Not sure how to take care of this. Any insight is appriciate
 
You can try using Screen.ActiveForm instead of Me. Personally, I would probably pass the form name and use that. That would avoid any possible ambiguity as to which form the action was intended for.
 
pbaldy, would you code the name as a varient?, not sure what it means to pass the form name, I will try the above, thanks for responding
 
You could either do

Function ClearAll(c As String, f As Form)

or

Function ClearAll(c As String, f As String)

You would then use them (untested):

f.Controls

or

Forms(f).Controls
 
I will try these, also Screen.ActiveForm did work, thanks for responding
 
Just tried
Function ClearAll(c As String, f As Form)

or

Function ClearAll(c As String, f As String)

You would then use them (untested):

f.Controls

or

Forms(f).Controls
Coud not get any combination to work, would this part need restating
Screen.ActiveForm ?, thanks
 
How did you call it? I just tested the string method, calling like so, and it worked perfectly:

ClearAll "blah", Me.Name
 
The correct way to use this function if passing the form is:

Code:
Function ClearAll(c As String, f As Form)
Dim ctl As Control
    For Each ctl In [COLOR=red][B]f[/B][/COLOR].Controls
       Select Case ctl.ControlType
       Case acTextBox, acComboBox, acListBox, acCheckBox
           If ctl.ControlSource = "" And ctl.Tag <> c Then
              ctl.Value = Null
           End If
      End Select
    Next ctl
End If
Simple change to the function - nothing special.

To call you use

Code:
ClearAll "test", Me
 

Users who are viewing this thread

Back
Top Bottom