Enabling/Disabling a field

usr33t

Registered User.
Local time
Today, 08:06
Joined
Dec 1, 2004
Messages
21
Hi,

I have a database which contains, amonst others, two fields;

(1) Treatment_provided - a YES/NO response being required.
(2) Number_of_days_of_treatment - a number field

When first opening the data entry form I would like a default value of "NO" in the Treatment_provided field, and the Number_of_days_of_treatment field to be disabled. Once Treatment_provided has been changed to "YES" I then want the Number_of_days_of_treatment field to become enabled,allowing me to enter a value. If the Treatment_provided field is then later changed back to "NO" I would like the Number_of_days_of_treatment field to clear and return to it's disabled state.

I can just about do this, but when I later review the data I have entered (having previously closed-down and re-opened the data-entry form) the Number_of_days_treatment field is greyed out, even on those records where Treatment_provided is "YES". The number values in the Number_of_days_of_treatment still remain however.

Does anyone know how to make sure that the Number_of_days_of_treatment field stays enabled even after the form has been closed and then re-opened for those records with "YES" in the Treatment_provided field? The Number_of_days_of_treatment field currently is defaulted to 'not enabled' and the Treatment_provided field defaults to "NO".

Does anyone know the VB code I might use to solve this problem? I appreciate that I may not have explained the problem well enough, so please let me know if you need further explanation.

If someone can help, that'd be great!

Thanks.

Best regards
Russell
Usr33t
 
you can try something like the following:

Code:
If Me.Treatment_Provided = True Then
Me.Number_Of_Days_Of_Treatment.Enabled = True
Else
Me.Number_Of_Days_Of_Treatment.Enabled = False
End If
 
Thanks for that!

That code seemed to work ok, and I can turn the field "off" and "on".

The only problem I have is that when I set the enabled property for the Number_of_days_ of_treatment field to "Yes" then it still remains enabled on new records and does not seem to react to the default value of "NO" in the Treatment_provided field.

If I set the enabled property for the Number_of_days_of_treatment field to "No" then all records where "YES" was selected in the Treatment_provided field have the Number-of_days_of_treatment greyed out.

I have the same code as you suggested but for some reason it doesn't react to the default value of "NO" in the Treatment_provided field. I guess I need a piece of code that says;

"When the user opens the record (and doesn't do anything else) check to see what value is in the Treatment_provided field. If it is "YES" then the Number_of_days_of_treatment should be enabled. If it is "NO" then the Number_of_days_of_treatment should be disabled"

I thought the code we have used would do this, but for some reason it's not!

Any ideas? Sorry to be so long winded in the explanation. I'm just trying to be as explicit as possible.

Thanks once again for your super-quick response.

Cheers
Russell
Usr33t
 
use another if statement

If Me.Treatment_Provided = False then
Me.Number_Of_Days_Of_Treatment.Enabled = False
 

Users who are viewing this thread

Back
Top Bottom