Making a control invisible

See my code below where I build up the OptionIDStr string.

The code crashes in the "IF" statement.
E.g. Me.OptionIDStr.Visible is not valid even tho' OptionIDStr contains "Option6" which is a control.

I understand the principle of what is wrong but cannot correct it.

Any thoughts out there??
For OptionID = 1 To 20
OptionIDStr = "Option" & OptionID

If Len(OptionIDStr & "") < 1 Then Me.OptionIDStr.Visible = 
False Else Me.OptionStr.Visible = True

Next OptionID

Open in new window

Patrick O'DeaAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Try this syntax:

If Len(OptionIDStr & "") < 1 Then Me(OptionIDStr).Visible =
0
 
als315Commented:
I don't understand your logic:
OptionIDStr = "Option" & OptionID
so Len(OptionIDStr & "") will be always more then 6.
What are you trying to check?
0
 
Patrick O'DeaAuthor Commented:
Thank you both,

...You are (obviously) totally correct als315 - my logic was a little suspect!

However, I managed to get it right.

By the way, experts, what is the precise logic of;
Me(OptionIDStr).Visible

When I put the Me followed by brackets ... what am I actually saying?
I think I know but would appreciate a comment from the experts.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
"Me" refers to the active object - in this case, your Form where this code is running. The default property of that object is the Controls collection, so referring to

Me(SomeControlName)

Is the same as writing

Me.Controls("SomeControlName")

Note that in your code, OptionIDStr is a VARIABLE, which means you do NOT enclose it in double quotes. If you are using ONLY the name of that control, then you would need to enclose it in double quotes.

So for a Variable, like you're using:

Me(YourVariableName)

If you instead use the actual Name of the Control:

Me("YourControlName")

And not to be nit-picky, but you're not using "brackets", you're using parentheses. A Bracket is [ or ] (i.e. a "square bracket"). They mean entirely different things to VBA, so be careful with your terminology.
0
 
Patrick O'DeaAuthor Commented:
Thanks all,

I'm learning!

Esp thanks to LSM for your comments
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
21Dewsbury:
Sorry, it was 1 am and I had to hit the sack. I did wait a bit for an initial response, but I guess we just missed each other.

mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.