Enabling/Disabling Controls Based On User?s Selection

  • Thread starter Thread starter Lirva Smith via AccessMonster.com
  • Start date Start date
L

Lirva Smith via AccessMonster.com

I don?t even know what code to post because I?ve been trying so many ways
to get this to work and I?m stumped. The only option I haven?t used is
Conditional Formatting and that?s because I?m not sure how that would work.

I?m using a continuous form. On the form there are 3 controls -
cboTransactionType, Deposit and Withdrawal. What I would like is, if the
user selects Deposit then the Withdrawal control is disabled and vise versa.

Can someone give me some assistance on this. Thanks!
 
The first is a combo box that have the two options "Deposit" and
"Withdrawal". The other 2 are text box.
 
So, if the user selects Deposit in the combo box, you want the textbox
labeled "Withdrawal" to be disabled?

Use the AfterUpdate event of the combo box to run this generic code:

Private Sub ComboBoxName_AfterUpdate()
Me.txtDeposit.Enabled = (Me.ComboBoxName.Value = "Deposit")
Me.txtWithdrawal.Enabled = (Me.ComboBoxName.Value = "Withdrawal")
End Sub
 
Yep! That is what I want to do, however, both controls (Deposit and
Withdrawal) are disabled so I'm not able to enter data. As well the entire
column is greyed out or disabled.

How can I ensure that it disable or enable each record (or row) at a time?

Thanks for your help.
 
You're using a continuous forms view, I take it. Is the combo box bound to a
field? What is the SQL statement of the combo box's Row Source? What is the
combo box's Bound Column?
 
1. Yes I'm using a continuous form.

2. The combo box is a bound field, the data comes from a look-up table.

Rowsource: lookup table
bound column: 1, column count: 2, column widths: 0;.5
 
So what you see in the combo box is not what is actually the value of the
combo box. Therefore, the example code I gave you won't work, because it
assumed that the combo box's value actually was Deposit or Withdrawal.
You'll need to replace those values in the code with the correct values from
the lookup table that are in column 1 of the combo box's Row Source. As you
didn't give me that info, I cannot provide more specific code.
 
Sorry about that Ken....Bear with me I'm learning.

So if I understand your last statement, because the value is not the actual
"Bound" value it won't work?

The bound value in column 1 is the "TransactionTypeID" and column 2 is the
actual text for the transaction type which is Deposit and Withdrawal.

I did a quick test and removed column 1 from the table, but the same thing
happened.
 
I did another test using a "value List" instead of the look-up table. It
brings me a bit closer to what I'm trying to do, in that now instead of
disabling both columns, it disables the column depending on what I select
from the combo - only now I need it to disable the control in that row.

Also, when I close and re-open the form the shade is gone.
 
The code needs to use the value of the TransactionTypeID that corresponds to
the two "display" texts. Again, I don't know what those values are, but
let's assume that 1 is Deposit and 2 is Withdrawal.

Private Sub ComboBoxName_AfterUpdate()
Me.txtDeposit.Enabled = (Me.ComboBoxName.Value = 1)
Me.txtWithdrawal.Enabled = (Me.ComboBoxName.Value = 2)
End Sub


As for what happens when you open the form, or when you move from one record
to another, you'd need to use the same code in the form's Current event:

Private Sub Form_Current()
Me.txtDeposit.Enabled = (Me.ComboBoxName.Value = 1)
Me.txtWithdrawal.Enabled = (Me.ComboBoxName.Value = 2)
End Sub


Note that, in ACCESS, when you change the "enabling" on one record, all
records in the form will change to show that enabling. This is because only
one record is actually "active" at a time in the form, but the controls that
you see are copies of the control that is active right now. Only way around
this is to use Conditional Formatting (in ACCESS 2002 and up -- may be
available in ACCESS 2000 as well) for the two textboxes, as this allows you
to set the disabled/enabled property for each record independently.
 
I Got it!!

Based on your comments I tried to work it through. This is what I've done:
I'm using Access 2000 so I have the option to use the conditional
formatting.

In my look-up table 1 = Deposit; 2=Withdrawal. So for the DEPOSIT control
I place this: [cboTransactionType]="2" and for the WITHDRAWAL control I
place this: [cboTransactionType]="1". Also, when I close and re-open the
form everything is still intact.

This can also be used when using a value list, actually I tested it with a
value list and from there I tried to figure out how to use it from the
table.

Thanks for your help!
 
Lirva said:
Based on your comments I tried to work it through. This is what I've done:
I'm using Access 2000 so I have the option to use the conditional
formatting.

In my look-up table 1 = Deposit; 2=Withdrawal. So for the DEPOSIT control
I place this: [cboTransactionType]="2" and for the WITHDRAWAL control I
place this: [cboTransactionType]="1". Also, when I close and re-open the
form everything is still intact.


I'm pretty sure you can use Conditional Formatting for
Enable/Disable. If you can, then each row will be grayed
out properly.

Try setting the CF entry for the Deposit text box to
Expression Is:
[cboTransactionType]=2
(I Don't think you want quotes around the 2)
and set the CF Disabled option.

Use 1 instead of 2 for the Witdrawal text box.
 
Back
Top