AllExperts > Experts 
Search      

Visual Basic

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Visual Basic Answers
Question Library

Ask a question about Visual Basic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Richard Rost
Expertise
I can answer any questions pertaining to Microsoft Visual Basic 6.0, Microsoft Access VBA, and the Visual Basic Language in general. I do NOT use VB.NET or VB 2005/08 much yet, so don't ask me any questions specific to those. Also, please feel free to check the Tips & Tricks section of my web site for VB tips.

Experience
I am the president of VBLearningZone.com and 599CD.com. I specialize in Microsoft Access and Visual Basic Tutorials. I have been teaching in the classroom since 1994, and online since 2002.

Education/Credentials
I am a self-taught VB expert. I have been building software for clients since the early 90s (and on my own since I was a child). You can see a sample of my Tutorials on my web site at 599CD.com

 
   

You are here:  Experts > Computing/Technology > Basic > Visual Basic > Access 2003 EVAL function

Topic: Visual Basic



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



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.