Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to evaluate expressions that don't return string or number?(Eval?) 1

Status
Not open for further replies.

ViAn

Technical User
May 7, 2003
30
NO
I want to edit the labels of my controls at run-time:

Code:
Forms!MyForm!Label2.Caption = "LabelTxt"

works well. But at run time the nr of the Label will change. Therefore I used the Eval function like I would have done in eg Matlab:

Code:
tmpString = "Forms!MyForm!Label" & idx & ".Caption = ""LabelTxt"""   ' idx:integer
Eval(tmpString)

Nothing happened. Is there any way to get this "Matlab-Eval-functionality" in Access and VBA?

Yours sincerely,
van
 
Try

Forms("Myform").Form!Label12 = "text"

John
 
You don't need Eval.
Just use the controls object of the form:

Forms!MyForm.controls("Label" & idx ).Caption = "LabelTxt"

hth

Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Thank you for the suggestion, but my problem is that I do not know if it is Label1, Label3 or Label12 which is to be changed until runtime. (That will be stored in the integer variable "idx").

Therefore I can not "hardcode" the Label Name. I also tried to put your suggestion into the Eval-function ( Eval(Forms(""Myform"").Form!Label" & idx & " = "text") ), but that did not give any improvement.

It would be to great help if there were a way to do this, except for writing A LOT of code.

-van

PS: I think you will have to append ".Caption" before the "="-sign in your suggestion.
 
Simple, but extraordinary helpful.
Thank you, Ben!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top