Disable Form Field (1 Viewer)

dspinner

Registered User.
Local time
Today, 02:34
Joined
Sep 26, 2002
Messages
16
How do you disable a field in a from based on data in another field. Example: If the Employee is "part time" i want certain fields to be disabled, so an entry cannot be made.
 

dcx693

Registered User.
Local time
Yesterday, 21:34
Joined
Apr 30, 2003
Messages
3,265
You need to have some kind of code run when an employee is flagged as "part time". Whichever field controls that flag needs to have code in the After Update event that deactivates the non-pertaining controls.

To disable a control, set it's Enabled property to false like using Visual Basic code like this:
Me.controlname.Enabled=False
this will still leave the field visible, but "dimmed" and non-clickable.

Read up in the Access help on how to assign code to form events.
 

fpendino

Registered User.
Local time
Yesterday, 20:34
Joined
Jun 6, 2001
Messages
73
Try putting this type of code into the After Update of the FullTime/Part Time field.


If txtFTPT = "PT" then
txtBenefits.enabled = false
txtSalary.enabled = false
end if
 

fpendino

Registered User.
Local time
Yesterday, 20:34
Joined
Jun 6, 2001
Messages
73
If you are just opeing a form put that code into the ON OPEN action of the form.
 

dcx693

Registered User.
Local time
Yesterday, 21:34
Joined
Apr 30, 2003
Messages
3,265
Sorry for the Friday afternoon temporary brain death...

First, this code is what you really need. You need code to disable and enable fields should the employee be a full timer or part-timer. Use code like this:

If Me.chkFullTime Then
 'Run these lines if employee is full time
 Me.control1.Enabled=False
 Me.control2.Enabled=False
Else
 'Run these lines if employee is part time
 Me.control1.Enabled=True
 Me.control2.Enabled=True
End If


Plus, it's probably best to put that code in the control's AfterUpdate event, but also in the Form's "On Current" event. As you browse from record to record, you need those particular form fields enabled or disabled in addition to when you change them from being full to part time within the same record.

If you put the code in the On Current event, you won't need to place it in the Open event.
 

Users who are viewing this thread

Top Bottom