By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,652 Members | 1,905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,652 IT Pros & Developers. It's quick & easy.

Greying Out One Field Based On Another

P: 11
I'm trying to use VBA code to disable a field based on the value of another field in a form. The code I have properly updates the enabled property of the field when it changes; however, it changes it for the form as a whole instead of a single record. My form is set as a single form.

For example on record 1, field1's value is "records" and field2's enabled property is set to false. When I go to the next record (record 2), field2's enabled property remains set to false even though field1's value is now "measurable" which should make field2's enabled property as true. Here's the code I have right now:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Field1_AfterUpdate()
  2. Me.Field2.Enabled = True
  3. If Me.Field1 = "records" Then
  4.     Me.Field2.Enabled = False
  5. ElseIf Me.Field1 = "measurable" Then
  6.     Me.Field2.Enabled = True
  7. End If
I've tried using a requery setting on the form and also on field1's properties of GotFocus, but I haven't had any success. Any help would be greatly appreciated.

Thanks!
Sep 16 '08 #1
Share this Question
Share on Google+
5 Replies


missinglinq
Expert 2.5K+
P: 3,532
Anytime you do something like this in the AfterUpdate event you also have to place the same code in the Form_Current event in order to persist the formatting as you move from record to record.

Welcome to Bytes!

Linq ;0)>
Sep 16 '08 #2

P: 50
Also, adding DoEvents after text field changes forces an immediate screen update instead of waiting for a later time. For many situations, it is the only way you are going to see the change.
Sep 16 '08 #3

missinglinq
Expert 2.5K+
P: 3,532
Also, adding DoEvents after text field changes forces an immediate screen update instead of waiting for a later time. For many situations, it is the only way you are going to see the change.
What are you talking about? DoEvents is not needed for the OP's code to work under any circumstance that I'm aware of! In point of fact, his code was changing the Enabled state of the other control without problem. The problem was that when Field2 was disabled in RecordA and the user moved to RecordB Field2 was also disabled there. Placing the code in the Form_Current event solves this.

DoEvents is primarily used to fix timing issue problems. It returns control from Access to Windows so that Windows can complete an operation, such as printing a report before Access tries to start printing a second report, or completing the running of one query before running another query, where the first must be completed before the second can be run with the correct results.
Sep 16 '08 #4

P: 11
Linq -

I added my code to the form's OnCurrent property and it does exactly what I want. Thanks for your help!
Sep 16 '08 #5

missinglinq
Expert 2.5K+
P: 3,532
Glad we could help!

Linq ;0)>
Sep 17 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.