Referring to properties

  • Thread starter Thread starter HB
  • Start date Start date
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
 
You're close.

With forms!frmname!ctrlnm
.visible = true
.enabled= true
.locked= true
.backcolor= 124
End With
 
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.
 
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)
 
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
 
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
 
Back
Top