Clear all default values by cycling through tagged controls

  • Thread starter Thread starter Leonard Priestley
  • Start date Start date
L

Leonard Priestley

I wanted to carry the current values of selected controls through to new
records. Storing the current data in the Default Value of the controls has
worked fine. Now I would like to clear all Default values by pressing one
command button.

I wanted to use code like:

Dim L As Control
For each L in Me.Controls
If L.Tag = "ThisOne" Then
L.DefaultValue = ""
End If
Next

But when I type a period after L, in the fourth line, I find the list that
is automatically displayed does not include any of the control's properties.
Can someone point me in the right direction?

By the way: not all of the controls are textboxes, two are checkboxes.
Also, I am writing this in Access 97.

Thanks,

Leonard Priestley
 
Since you are using a variable to refer to the control(s), Access cannot
determine the type of control until the code is running. Therefore,
intellisense will only show those properties that are common to all controls.
Even though that is the case, you can still use the property. If you do and the
control that is currently in the loop does NOT have the property and the
property gets called then an error will be generated.

For instance, labels are controls, but they don't have a defaultvalue. Your
code as written should work with no problems as long as you only tag controls
that have a defaultvalue property.
 
The controls properties differ from text box to check box etc, therefore you
see what is common to all. Try the following

Dim L As Control
For Each L In Me.Controls

If L.Tag = "ThisOne" Then


If TypeOf L Is TextBox Then L.Value = ""
If TypeOf L Is CheckBox Then L.Value = False

End If
Next

and no, you won't see the intellitype unless you redimension L as checkbox
etc. . .
 
When you are using a "generic" Control object, intellisense is
displaying only those properties and methods that are common to all
controls. As you have probably found out you can still use them.

To get more specific you would have to reference a specific type of
control.

- Jim
 
Back
Top