Enable/Disable multipule text boxes based on any text in another textbox

M

Mesa

Thankyou Jeff, this is the closest thing I have gotten. So far, I have
a textbox
labeled "College or University", and I want to be able to type any
value for it to enable 2 other textboxes labeled "Degree" and "Field of
Study". How can I code this so that I can just type anything in the
"College or University" textbox and it enables the other two and also
if nothing is typed it will stay disabled. Your help is VERY
appreciated!!! This is what I got so far below...

Private Sub College_or_University_Change()
blnEnabled = Len(Nz(College or University)) > 0
Me![Degree].Enabled = blnEnabled
Me![Field of Study].Enabled = blnEnabled
End Sub

Complements to Jeff for this coding.

P.S. Im sorry if I reply late but im in Iraq and I can ony reply when
Im on Radio Guard. This is part of a database I am making to manage
personnel in battalion because of the system we have enplaced is not
very great. "Infantry all the way, AIRBORNE!"
 
D

Douglas J. Steele

When you've got spaces in the name of a field or control, you need to put
square brackets around the name (note that most of us recommend very
strongly not to use embedded spaces). I'd recommend putting the code in the
text box's AfterUpdate event, not the Change event. (Change fires with every
key stroke: not really required). Try:

Private Sub College_or_University_AfterUpdate()
blnEnabled = Len(Me.[College or University] & "") > 0
Me![Degree].Enabled = blnEnabled
Me![Field of Study].Enabled = blnEnabled
End Sub

BTW, the fact that the code above compiles implies to me that you haven't
got Access set to force declaration of all variables (unless you've defined
blnEnabled as a public variable). That's a bad idea, since you could have
mistyped variable names in your code, and you'd never know it. For instance,
you're defining blnEnabled as the variable, but you could mistakenly have

Me![Degree].Enabled = blnEnable
Me![Field of Study].Enabled = blnEnable

and your fields would always be disabled (since blnEnable would always be
False)

Put Option Explicit at the top of each module. To have Access automatically
put that for you from now on, go to Tools | Options while you're in the VB
Editor. Go the Module tab, and make sure "Require Variable Declaration" is
checked.
 
M

Mesa

Thankyou SOOOOO much man, you are ****in great, this saved me weeks of
mindless labor over. The code worked perfectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top