Disabling Text box controls

C

Carlos1815

I have a project where I would like the text box controls of a form to
be disabled according to the choice made from a combo box. I've seen
questions similar to this many times in this forum, but none of the
answers seem to work for me. Here's what I have:

A form with text box controls to enter data. I also have a combo box
with two choices. Choice A, all the text box controls are Enabled.
If Choice B is chosen, I would like all the text boxes to be disabled
and greyed out, but only for those records that have "Choice B"; all
other records that have "Choice A" in the combo box, I would like to
leave the text boxes enabled.

On the combo box After Update event, I have this code (cboPageType is
the combo box, and PageName and Text are the names of two of the text
boxes I would like disabled upon choosing "Choice B", which in this
case is "CompCheck_Page"):

Private Sub cboPageType_AfterUpdate()
If Me.cboPageType = "CompCheck_Page" Then
Me.PageName.Enabled = False
Me.Text.Enabled = False
Else
Me.PageName.Enabled = True
Me.Text.Enabled = True
End If
End Sub

However, nothing happens when I choose "Choice B" or "Choice A"; as if
the code doesn't exist. The combo box is bound to a separate table
with the two choices in it. I think that's all the information I
have. If anyone can see an answer to this conunudrum, I would
appreciate any help! Thank you.

Carlos
 
C

Carlos1815

Forgot to add, in order for the enable/disable to be maintained as you move
from record to record, the same code needs to be in the form's OnCurrent
event as well as the AfterUpdate event.





Linq said:
It worked without problem for me!
The obvious; are all your names spelled correctly? Is CompCheck_Page the
exact spelling of this choice?
What exactly do you mean by
However, nothing happens when I choose "Choice B" or "Choice A"
The controls have to be either enabled or disabled to begin with, so onlyone
choice should do something, right? .
From Form Design View, select the combobox then goto  Properties - Events.
Does [Event Procedure] appear next to the AfterUpdate Property? If not, click
in the box, select Build Code. This should take you to the AfterUpdate sub.
Exit the code module and run the form again.
Lastly, I guess you have to think about a corrupted combobox.
BTW, you should change the name of your textbox from Text to something else;
Text is a reserved word in Access.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200804/1- Hide quoted text -

- Show quoted text -

Thank you for your prompt help! Unfortunately, nothing is fixed. I
changed the name of the text boxes, PageName and Text to Screentitle
and InstructionalText respectively. The code for the cbo box After
Update now looks like this:

Private Sub cboPageType_AfterUpdate()
If Me.cboPageType = "CompCheck_Page" Then
Me.ScreenTitle.Enabled = False
Me.InstructionalText.Enabled = False
Else
Me.ScreenTitle.Enabled = True
Me.InstructionalText.Enabled = True
End If
End Sub

I also made sure to make the name changes in the Table, as well. The
name of the combo box and the contents of the cbo box remain the
same. I also made sure to add that previous code into the form's
OnCurrent event. The [Event Procedure] is present in the cbo box's
After Update and the form's On Current properties.

To clear up what I described previously, what I have is a form with
all text controls enabled; this is the default setting for the whole
form. What I would like to have is certain text box controls disabled
when Choice B from the cbo box is chosen for that record. So maybe in
records 1 through 7, Choice A is chosen from the cbo box and are
normal and text boxes enabled, but record 8 has Choice B chosen in the
cbo box, so I would like certain text boxes disabled for that record
only and for any other records where Choice B is chosen from the cbo
box.

How would I know if the cbo box is corrupted? Other than it not
working?

As an addendum, I would like to have the same functionality with a
button; making it invisible until Choice B is chosen on the cbo box.
I tried making a button and coding it to be invisible until the cbo
box event, but that doesn't work, either. The button remains
invisible regardless; I'd have to make it visible by switching the
Visible property to "yes".

I don't know if this matters, but I'm using Access 2002.

Thanks again!
Carlos
 
C

Carlos1815

Forgot to add, in order for the enable/disable to be maintained as you move
from record to record, the same code needs to be in the form's OnCurrent
event as well as the AfterUpdate event.
Linq said:
It worked without problem for me!
The obvious; are all your names spelled correctly? Is CompCheck_Page the
exact spelling of this choice?
What exactly do you mean by
However, nothing happens when I choose "Choice B" or "Choice A"
The controls have to be either enabled or disabled to begin with, so only one
choice should do something, right? .
From Form Design View, select the combobox then goto  Properties - Events.
Does [Event Procedure] appear next to the AfterUpdate Property? If not,click
in the box, select Build Code. This should take you to the AfterUpdate sub.
Exit the code module and run the form again.
Lastly, I guess you have to think about a corrupted combobox.
BTW, you should change the name of your textbox from Text to something else;
Text is a reserved word in Access.
Answers/posts based on Access 2000/2003
Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200804/1-Hide quoted text -
- Show quoted text -

Thank you for your prompt help!  Unfortunately, nothing is fixed.  I
changed the name of the text boxes, PageName and Text to Screentitle
and InstructionalText respectively.  The code for the cbo box After
Update now looks like this:

Private Sub cboPageType_AfterUpdate()
  If Me.cboPageType = "CompCheck_Page" Then
       Me.ScreenTitle.Enabled = False
       Me.InstructionalText.Enabled = False
    Else
        Me.ScreenTitle.Enabled = True
        Me.InstructionalText.Enabled = True
  End If
End Sub

I also made sure to make the name changes in the Table, as well.  The
name of the combo box and the contents of the cbo box remain the
same.  I also made sure to add that previous code into the form's
OnCurrent event.  The [Event Procedure] is present in the cbo box's
After Update and the form's On Current properties.

To clear up what I described previously, what I have is a form with
all text controls enabled; this is the default setting for the whole
form.  What I would like to have is certain text box controls disabled
when Choice B from the cbo box is chosen for that record.  So maybe in
records 1 through 7, Choice A is chosen from the cbo box and are
normal and text boxes enabled, but record 8 has Choice B chosen in the
cbo box, so I would like certain text boxes disabled for that record
only and for any other records where Choice B is chosen from the cbo
box.

How would I know if the cbo box is corrupted?  Other than it not
working?

As an addendum, I would like to have the same functionality with a
button; making it invisible until Choice B is chosen on the cbo box.
I tried making a button and coding it to be invisible until the cbo
box event, but that doesn't work, either.  The button remains
invisible regardless; I'd have to make it visible by switching the
Visible property to "yes".

I don't know if this matters, but I'm using Access 2002.

Thanks again!
Carlos- Hide quoted text -

- Show quoted text -

I found the problem! There were two columns in the Table bound to the
cbo box, I had the code refer to the wrong column. I set it to
recognize the correct column in the Table, and the form functions like
I mentioned. Thanks for your insight!

Carlos
 

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