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

M

Mesa

Ok, this is a continuation of my last post. My problem is I want to
make 1 textbox control two other text boxes. If I type any text into a
textbox called "collegeoruniversity", I want the other two text boxes
called "degree" and "fieldofstudy" to enable and if there is no text at
all i want them to be disabled.

This code below works to do all that I ask but there is one problem


Private Sub CollegeorUniversity_AfterUpdate()
blnEnabled = Len(Me.[CollegeorUniversity] & "") > 0
Me![Degree].Enabled = blnEnabled
Me![FieldofStudy].Enabled = blnEnabled
End Sub


The inconvienience is that I have to click out of the box in order to
enter a value in "degree" or "fieldofstudy". This is because it wont
apply the code until after I update by clicking out of the box. My
guess is that I need to apply the "Change()" command but it will not
work properly when I applied it. I am very thankfull for the help that
got me this far.

I also am trying to apply coding for the "Form_Current()" so that when
I go to the next record the proper textbox properties will apply.

"Infantry leads the way! Airborne, all the way!"
 
R

Rick Brandt

Mesa said:
Ok, this is a continuation of my last post. My problem is I want to
make 1 textbox control two other text boxes. If I type any text into
a textbox called "collegeoruniversity", I want the other two text
boxes called "degree" and "fieldofstudy" to enable and if there is no
text at all i want them to be disabled.

This code below works to do all that I ask but there is one problem


Private Sub CollegeorUniversity_AfterUpdate()
blnEnabled = Len(Me.[CollegeorUniversity] & "") > 0
Me![Degree].Enabled = blnEnabled
Me![FieldofStudy].Enabled = blnEnabled
End Sub


The inconvienience is that I have to click out of the box in order to
enter a value in "degree" or "fieldofstudy". This is because it wont
apply the code until after I update by clicking out of the box. My
guess is that I need to apply the "Change()" command but it will not
work properly when I applied it. I am very thankfull for the help that
got me this far.

I also am trying to apply coding for the "Form_Current()" so that when
I go to the next record the proper textbox properties will apply.

For the Change event you need to refer to the Text property of the control
rather than the Value property. Value being the default is what you get when
you refer to the control name only.

Private Sub CollegeorUniversity_AfterUpdate()
blnEnabled = Len(Me.[CollegeorUniversity].Text & "") > 0
Me![Degree].Enabled = blnEnabled
Me![FieldofStudy].Enabled = blnEnabled
End Sub

Note that the Text property of a control is only accessible while the control
has focus. That should never be a problem for the change event, but cannot be
guaranteed in many other events.
 
M

Mesa

Thankyou Rick, that sums it up. The additional coding worked
flawlessly. Now I can concentrate on getting it to work on
"Form_Current".
 
R

Rick Brandt

Mesa said:
Thankyou Rick, that sums it up. The additional coding worked
flawlessly. Now I can concentrate on getting it to work on
"Form_Current".

In form Current you would use the Value property instead of Text, but it would
otherwise be pretty much the same code.
 
M

Mesa

Thankyou again Rick. I am trying to apply it to the Form_Current
function and it looks like this

Select Case CollegeorUniversity
blnEnabled = Len(Me.[CollegeorUniversity].Value & "") > 0
Me![Degree].Enabled = blnEnabled
Me![Field of Study].Enabled = blnEnabled
End Select

But I get an error message that looks like this ---> Compile Error,
Statements and labels invalid between select case and first case.

I have an idea why and thats because its a select case, but I dont know
what other way to imbeded it to Form Current. Thankyou again for your
post.
 
R

Rick Brandt

Mesa said:
Thankyou again Rick. I am trying to apply it to the Form_Current
function and it looks like this

Select Case CollegeorUniversity
blnEnabled = Len(Me.[CollegeorUniversity].Value & "") > 0
Me![Degree].Enabled = blnEnabled
Me![Field of Study].Enabled = blnEnabled
End Select

But I get an error message that looks like this ---> Compile Error,
Statements and labels invalid between select case and first case.

I have an idea why and thats because its a select case, but I dont
know what other way to imbeded it to Form Current. Thankyou again
for your post.

You don't need the Case block at all. Your second line is already handling both
possible conditions.

Just remove the first and last lines.
 

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