Referring to properties

H

HB

Can I refer to a controls property using a string much like I can a Control.

I want to simplify the following code:

forms!frmname!ctrlnm.visible = true
forms!frmname!ctrlnm.enabled= true
forms!frmname!ctrlnm.locked= true
forms!frmname!ctrlnm.backcolor= 124
etc

I tried:

with forms!frmname!ctrlnm
.("visible") = true
etc

but it doesn't work - Is there a collection name I should be using or is
there a better way

Thjanks in advance
 
W

Wayne Morgan

You're close.

With forms!frmname!ctrlnm
.visible = true
.enabled= true
.locked= true
.backcolor= 124
End With
 
G

Graham Mandeno

You want either:

with forms!frmname!ctrlnm
.visible = true

or, if you really need to use a string:

with forms!frmname!ctrlnm
.Properties("visible") = true

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.
 
C

Chip Pearson

I think the closest you can get is to use CallByName.

Load UserForm1
CallByName UserForm1.TextBox1, "Text", VbLet, "New Text"
UserForm1.Show


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
H

HB

OOPs

I probably didn't explain my question good enough

I eventually want to use an array with string values of the name & the value
in a for each statement so I need to be able to have the property in string
form ie form!frmname!ctrlname(propstring)


Thanks Morgan & all
 
J

Jack

You are complicating things. It is simply:

With Forms!frmname!ctrlnm
.Visible = True
.Enabled = True
...
...
etc.
End With
 
W

Wayne Morgan

In that case, Graham gave you the way to go, we just need to back it up to the control's
name. Using the .Controls("name") method will allow you to concatenate together a name.

For i = 1 To 10
With forms!frmname
.Controls("ctrlnm" & i).visible = true
.Controls("ctrlnm" & i).enabled= true
.Controls("ctrlnm" & i).locked= true
.Controls("ctrlnm" & i).backcolor= 124
End With
Next i
 
J

Jack

I'm a little confused. If you want to create a FOR EACH
loop, do you want to loop through the CONTROLS collection
or the PROPERTIES collection or both? In a FOR EACH loop
you do not have to create strings. You just have to
dimension a variable as a control or a property and use it
accordingly in the loop.
 

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