code to disable an item

sdkramer

Registered User.
Local time
Today, 14:40
Joined
Mar 19, 2002
Messages
64
I have a checkbox call it chkBox if it is checked I want several fields enabled (eg. chkHere), if not I want them disabled. how do I do this I know I need an on update event for chkBox but I don't know what code will test for checked, and I don't know how to disable the item.
 
should go something like this, on the after update of the checkbox put

if Me!NameOfCheckBox = -1 then
Me!NameofControlToEnableDisable.Enabled = False
Else
Me!NameofControlToEnableDisable.Enabled = True
Endif


[This message has been edited by Geoff Codd (edited 04-03-2002).]
 
Ok Here's what I have: What seems to be the matter.

Private Sub ABE_Part_AfterUpdate()
If Me!ABE_Part = -1 Then
Me!AccompABEBeginningBE.Enabled = False
Me!AccompABEBeginningLit.Enabled = False
Me!AccompABEBeginningLitDate.Enabled = False
Me!AccompABEIntermedHi.Enabled = False
Me!AccompABEIntermedHiDate.Enabled = False
Me!AccompABEIntermedLow.Enabled = False
Me!AccompABEIntermedLowDate.Enabled = False
Me!AccopmABEBeginningBEDate.Enabled = False
Else
Me!AccompABEBeginningBE.Enabled = False
Me!AccompABEBeginningLit.Enabled = False
Me!AccompABEBeginningLitDate.Enabled = False
Me!AccompABEIntermedHi.Enabled = False
Me!AccompABEIntermedHiDate.Enabled = False
Me!AccompABEIntermedLow.Enabled = False
Me!AccompABEIntermedLowDate.Enabled = False
Me!AccopmABEBeginningBEDate.Enabled = False
End If
 
Try This

Private Sub ABE_Part_AfterUpdate()
If Me!ABE_Part = -1 Then
Me!AccompABEBeginningBE.Enabled = False
Me!AccompABEBeginningLit.Enabled = False
Me!AccompABEBeginningLitDate.Enabled = False
Me!AccompABEIntermedHi.Enabled = False
Me!AccompABEIntermedHiDate.Enabled = False
Me!AccompABEIntermedLow.Enabled = False
Me!AccompABEIntermedLowDate.Enabled = False
Me!AccopmABEBeginningBEDate.Enabled = False
Else
Me!AccompABEBeginningBE.Enabled = True
Me!AccompABEBeginningLit.Enabled = True
Me!AccompABEBeginningLitDate.Enabled = True
Me!AccompABEIntermedHi.Enabled = True
Me!AccompABEIntermedHiDate.Enabled = True
Me!AccompABEIntermedLow.Enabled = True
Me!AccompABEIntermedLowDate.Enabled = True
Me!AccopmABEBeginningBEDate.Enabled = True
End If
 
You can halve your code by doing this...

Private Sub ABE_Part_AfterUpdate()
Dim blnABE_Part as Boolean
blnABE_Part = Not(CBool(Me.ABE_Part))

Me!AccompABEBeginningBE.Enabled = BlnABE_Part
Me!AccompABEBeginningLit.Enabled = blnABE_Part
Me!AccompABEBeginningLitDate.Enabled = blnABE_Part
Me!AccompABEIntermedHi.Enabled = blnABE_Part
Me!AccompABEIntermedHiDate.Enabled = blnABE_Part
Me!AccompABEIntermedLow.Enabled = blnABE_Part
Me!AccompABEIntermedLowDate.Enabled = blnABE_Part
Me!AccopmABEBeginningBEDate.Enabled = blnABE_Part

Ian
 
Additionally, if you want to be a bit more dynamic about things you can use a controls tag property as an indicator as to whether it should be enabled or not suchas...

'set boolean variable
Dim blnABE_Part as Boolean
blnABE_Part = Not(CBool(Me.ABE_Part))

'loop controls and set dependent on tag property
Dim ctl As Control

For Each ctl In Me.Controls
If ctl.Tag = "X" Then 'toggle enabled
ctl.Enabled = blnABE_part
End If
Next ctl


The functionality added here is that you can add controls to the form at a later date or delete them without fear of your code being wrong - all you need to remember is if you add a control you need to put an "X" in the tag property.

Ian
 
I wasn't able to get it to work with the Me! in front of it. but it seemed to work when it was removed. I'll try some of the other suggestions.
 

Users who are viewing this thread

Back
Top Bottom