Disable multiple fields based on lookup value of seperate field

G

Guest

I have a transactions detail form for entering financial transactions in a
transaction detail table. One of the fields in this form is an account
lookup field to specify which account to charge the transaction to. I would
like to disable three other fields when the account field is set to the
mileage account. Can anyone help?
 
T

tina

well, to start with, i hope by "account lookup field", you mean a combo box
control in the form that is bound to the account field in the underlying
table. if you actually have a "lookup" field in your table, i strongly
recommend you get rid of it. first, it causes a lot of problems in places
you wouldn't expect (see http://www.mvps.org/access/lookupfields.htm for
details), and second, you don't need it. you can easily create a combo box
in a form, using a wizard that looks almost identical to the wizard that
creates a table lookup field. the difference is that creating a combo box in
a form has absolutely none of the bad fallout that you get with a lookup
field in a table.

having said that, it's relatively easy to manipulate controls on a form
based on a value in the current record. to do it with VBA, put the following
lines of code in the combo box's AfterUpdate event procedure, and also in
the form's Current event procedure, as

Dim blnValue As Boolean

With Me
blnValue = Not (!cboAccount = "mileage")
!FieldOne.Enabled = blnValue
!FieldTwo.Enabled = blnValue
!FieldThree.Enabled = blnValue
End With

in the form, your combo box control should be bound to the account field in
the form's underlying table. in the code above, substitute the correct name
of the combo box for "cboAccount". and substitute the correct names of the
"other three" controls for FieldOne, FieldTwo, and FieldThree.

note: in situations like this, i usually go a step further, and set the
value in the disabled controls to Null. otherwise, the user might enter an
account name, enter a value in any of those other three controls, then go
back and change the account name to "mileage" - leaving the controls
disabled but with values still in them.

hth
 

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