| |
You are here: Experts > Computing/Technology > Basic > Visual Basic > Access 2003 EVAL function
Expert: Richard Rost
Date: 8/25/2008
Subject: Access 2003 EVAL function
Question Hi Richard:
I am trying to modify the enabled & locked controls for a group of text boxes in a form in Access 2003. They depend on a specific trimester.
For example, first trimester text boxes are labeled as shown in coding below.
With CurrentFormToSetup
.AllowEdits = True
.txtR_T1_Skill01.Enabled = True
.txtR_T1_Skill01.Locked = False
.txtR_T1_Skill02.Enabled = True
.txtR_T1_Skill02.Locked = False
.txtR_T1_Skill03.Enabled = True
.txtR_T1_Skill03.Locked = False
.txtR_T1_Skill04.Enabled = True
.txtR_T1_Skill04.Locked = False
(and so on)
Is there a way to use the EVAL function so that I can set say Current Trimester to 1, 2, or 3 depending on which set of controls I want to change and modify the code above so that I can use a FOR Loop 1 to 3 and thus don't have to list the code for 2nd and 3rd trimester separately as below, (only 2nd trimester shown here)
.txtR_T2_Skill01.Enabled = True
.txtR_T2_Skill01.Locked = False
.txtR_T2_Skill02.Enabled = True
.txtR_T2_Skill02.Locked = False
.txtR_T2_Skill03.Enabled = True
.txtR_T2_Skill03.Locked = False
.txtR_T2_Skill04.Enabled = True
.txtR_T2_Skill04.Locked = False
(and so on)
I tried for example EVAL(".txtR_T" & CurrrentTrimester & "_Skill01.Enabled = True"), but I get an error.
Some of my forms have more 10 or more text boxes for each trimester, so it would really shorten my coding if I could do that.
Thanks
Answer Yes, you would have to rename your boxes though.
Create a CONTROL ARRAY. If you copy one text box and paste it, VB asks you if you want to create a control array. Say YES. Now you'll have
MyTextBox(0)
MyTextBox(1)
Which you can then easily control with a loop...
For X = 0 to 10
MyTextBox(X).Visible = False
Next X
For example.
That's the EASIEST solution.
Let me know if you have any other questions or comments.
Also, be sure to visit my FREE Tips & Tricks Page at http://www.599cd.com/tips?key=AllExperts
Cordially,
Richard Rost
599CD Computer Training
http://www.599cd.com
P.S. Try one of my FREE tutorials at http://www.599cd.com/VB?key=AllExperts
P.P.S. I volunteer my time at AllExperts to help people, and I get a LOT of questions, so I can't take an hour to answer each question. If you need more DETAILED HELP, come to my TechHelp web site at http://www.599cd.com/TechHelp/AllExperts and I'll take as much time as you need to answer your question.
Add to this Answer
Ask a Question
|
|