cannot find 'value' in the properties colletcion...

R

rocco

Hello,
I have a form with many controls of different type.
I'm building a procedure to clean the value of any controls.
This is what I wrote:
---------
Dim ctl As Control
Dim i As Integer
For Each ctl In Me.Controls

For i = 0 To Me.Controls(ctl.name).Properties.Count - 1
If Me.Controls(ctl.name).Properties(i).Name = "Value" Then
ctl.Value = Null
Exit For
End If
Next
Next
-----------------
It runs...but doesn't do anything.
I checked it against a combobox and it has come out it never finds the value
property iterating the collection.
How could this happen?

Thanks,
Rocco
 
M

Marshall Barton

rocco said:
I have a form with many controls of different type.
I'm building a procedure to clean the value of any controls.
This is what I wrote:
---------
Dim ctl As Control
Dim i As Integer
For Each ctl In Me.Controls

For i = 0 To Me.Controls(ctl.name).Properties.Count - 1
If Me.Controls(ctl.name).Properties(i).Name = "Value" Then
ctl.Value = Null
Exit For
End If
Next
Next


If you have no way to identify which controls should be
reset, then a common way to do that is:
 
M

Marshall Barton

rocco said:
I have a form with many controls of different type.
I'm building a procedure to clean the value of any controls.
This is what I wrote:
---------
Dim ctl As Control
Dim i As Integer
For Each ctl In Me.Controls

For i = 0 To Me.Controls(ctl.name).Properties.Count - 1
If Me.Controls(ctl.name).Properties(i).Name = "Value" Then
ctl.Value = Null
Exit For
End If
Next
Next


Sorry if there was an incomplete reply.

Try using:

On Error Resume Next 'ignore ctl without Value
For Each ctl In Me.Controls
ctl.Value = Null
Next ctl
 
R

rocco

thank you,
that is what I have done.
i was just wondering why I cannot find 'value' in the properties collection.
Just trying to learn something...
 
M

Marshall Barton

rocco said:
i was just wondering why I cannot find 'value' in the properties collection.
Just trying to learn something...


Your guess is as good as mine. I suspect it's because the
property has no meaning until the form is loaded so it was
implemented as an internal property. (I have it from a
"reliable source" that there are a lot of internal
properties that we can not use at any time.)
 
R

rocco

Thanks you very much for this hint !!


Marshall Barton said:
Your guess is as good as mine. I suspect it's because the
property has no meaning until the form is loaded so it was
implemented as an internal property. (I have it from a
"reliable source" that there are a lot of internal
properties that we can not use at any time.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top