473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Greying Out One Field Based On Another

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
5 3562
missinglinq
3,532 Expert 2GB
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
Krandor
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
3,532 Expert 2GB
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
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
3,532 Expert 2GB
Glad we could help!

Linq ;0)>
Sep 17 '08 #6

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

Similar topics

3
by: Rob Dixon | last post by:
Hi. Am I missing something, or is there no way of greying out irrelevant form fields on the basis of the contents of the rest of the form? Thanks, Rob
6
by: Greg | last post by:
I am trying to change the value of one field in my query based on the value in another. If Field 1 had the text "ONACCNT" then in Feild 2 I want the date to change to today's date. Any help would...
3
by: Jim | last post by:
Hey all, I have a dilemma. I have a field in a table called "Supervisor." The table currently has 1,500+ records. Sometimes, the HR download that populates the field formats the field one way,...
2
by: Danny | last post by:
Hello I am trying to create a separate listbox and fill it with items based on what is in another field in a database. This field is bound to a field in the underlying database. But the data...
8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
0
by: Ray Holtz | last post by:
Is it possible to autofill a field based on what is entered into another field in a form? My form has an employee field, and department field. In an Items Table, I have fields FldEmployee, and...
7
by: astro | last post by:
Anyone have suggestions on where to troubleshoot this error? Background: -Access 2k v. 9.0.6926 sp3 - front and backend on production server (wiindows 2k) -accessed via Citrix -front-end is...
2
by: AA Arens | last post by:
Somebody willing to assist me in the following? I want to have values from one field copied to another field when I choose choose a item from a drop down menu. I have 2 forms: 1 Company...
5
by: lsimonelli via AccessMonster.com | last post by:
On a form, how do I require entry of a field based on the data in another field? I do not want to require at the table level. I have a field that the user selects where a refund goes. If they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.