By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,122 Members | 921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,122 IT Pros & Developers. It's quick & easy.

Execute a string as an object

mshmyob
Expert 100+
P: 903
I create a text string like so in a loop

vBox = "Me.txtLetter" & CStr(vCounter) & ".visible=true"

This will result in vBox = "Me.txtLetter1.visible=true"
The number 1 will cycle through all the way to 26 if need be

There are 26 boxes on my screen a and I want to turn them on or off.

I need to execute vBox.

I hope you understand what I am trying to say. Is there anyway to do it in Access. I know in the old DOS dbase days you could just say &vBox and it would convert what was in the vBox variable into a statement.
Jan 9 '08 #1
Share this Question
Share on Google+
7 Replies


Rabbit
Expert Mod 10K+
P: 12,357
The usual way of doing this is:
Expand|Select|Wrap|Line Numbers
  1. Me.Controls("txtLetter" & vCounter).Visible = True
  2.  
Jan 9 '08 #2

mshmyob
Expert 100+
P: 903
Rabbit you are a GENIUS!!! Thanks it worked perfectly.

The usual way of doing this is:
Expand|Select|Wrap|Line Numbers
  1. Me.Controls("txtLetter" & vCounter).Visible = True
  2.  
Jan 9 '08 #3

Rabbit
Expert Mod 10K+
P: 12,357
Not a problem.
Jan 9 '08 #4

mshmyob
Expert 100+
P: 903
Just out of curiosity is there a way to do what I asked in case I need to do it in the future.

Not a problem.
Jan 9 '08 #5

Rabbit
Expert Mod 10K+
P: 12,357
Just out of curiosity is there a way to do what I asked in case I need to do it in the future.
Not that I know of, you can try the Evaluate() function but I don't think it evaluates vba.

But it doesn't matter, I can't think of a time when you'd have to do it that way.
Jan 9 '08 #6

ADezii
Expert 5K+
P: 8,623
I create a text string like so in a loop

vBox = "Me.txtLetter" & CStr(vCounter) & ".visible=true"

This will result in vBox = "Me.txtLetter1.visible=true"
The number 1 will cycle through all the way to 26 if need be

There are 26 boxes on my screen a and I want to turn them on or off.

I need to execute vBox.

I hope you understand what I am trying to say. Is there anyway to do it in Access. I know in the old DOS dbase days you could just say &vBox and it would convert what was in the vBox variable into a statement.
To the best of my knowledge, there is no way that this can be accomplished in Access via the manner which you describe. The Eval() Function can not be used in this context, also. Rabbit described the only sensible Method of cycling through all 26 Text Boxes named txtLetter1 thru txtLetter26, if you so desired. To expand on Rabbit's Reply:
Expand|Select|Wrap|Line Numbers
  1. Const conNumOfControls As Integer = 26
  2. Dim intCounter As Integer
  3.  
  4. For intCounter = 1 To conNumOfControls
  5.   Me.Controls("txtLetter" & CStr(intCounter)).Visible = False
  6. Next
Jan 10 '08 #7

mshmyob
Expert 100+
P: 903
Thanks. I did get Rabbit's suggestion to work and it works beautifully. I was just wondering if it could be done the way I originally was thinking. It appears it cannot.

To the best of my knowledge, there is no way that this can be accomplished in Access via the manner which you describe. The Eval() Function can not be used in this context, also. Rabbit described the only sensible Method of cycling through all 26 Text Boxes named txtLetter1 thru txtLetter26, if you so desired. To expand on Rabbit's Reply:
Expand|Select|Wrap|Line Numbers
  1. Const conNumOfControls As Integer = 26
  2. Dim intCounter As Integer
  3.  
  4. For intCounter = 1 To conNumOfControls
  5.   Me.Controls("txtLetter" & CStr(intCounter)).Visible = False
  6. Next
Jan 10 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.