Disable or lock check box after entry

swift

Registered User.
Local time
Today, 11:21
Joined
Mar 12, 2006
Messages
67
Hi,

I'm looking for some help with my latest project, hope someone can help!! Basically I have a form that contains two check boxes, StartedAgrBr and CompletedAgrBr.
I want to make sure that when a user selects StartedAgrBr (for example), they cannot unselect it. So I need some code to either disable or lock the check box after the user has ticked it.

I've trawled the site for the past hour and had a go at the code myself to no avail - please can anyone offer any advice.

Cheers

Swift
 
Hi Swift

You could try this:
Code:
Private Sub StartedAgrBr_AfterUpdate()
If Me.ActiveControl = True Then
Me.Dirty = False
Me.CompletedAgrBr.SetFocus
Me.StartedAgrBr.Enabled = False
End If
End Sub
 
Spot on Bob Fitz, thanks for the help!
:)
Swift
 
A couple of things:

Using this code only in the AfterUpdate event of the Checkbox has a problem! Once it has been Disabled, the Checkbox will be Disabled on every Record in your Form, even New Records! To avoid this problem, you need to also place this code in the Form_Current event of the Form, with a slight modification.
Code:
Private Sub Form_Current()
 If Me.ActiveControl = True Then
  Me.Dirty = False
  Me.CompletedAgrBr.SetFocus
  Me.StartedAgrBr.Enabled = False
 Else
  Me.StartedAgrBr.Enabled = True
 End If
End Sub
Another possible problem concerns what happens if the user accidentally ticks the Checkbox and realizes that they've made a mistake? They have no way to correct their error.

I usually handle this kind of thing by only Locking or Locking/Disabling the Control after the Record has been saved. This allows the user to correct their mistake at the time the data is being entered, but not at a later date. To do this you'd only place the code above in the Form_Current event.

One last thing is a matter of style, concern using the Enabled Property. With

Enabled = False

the Checkbox will now be greyed out, not a look that everyone wants. The attached Label is also greyed out, making recognition of Control's purpose difficult. Using

Locked = True

or

Enabled = False
Locked = True

will keep the Control from being changed without graying out the Control and Label.

Linq ;0)>
 
Last edited:
A couple of things:
One last thing is a matter of style, concern using the Enabled Property. With

Enabled = False

the Checkbox will now be greyed out, not a look that everyone wants. The attached Label is also greyed out, making recognition of Control's purpose difficult. Using

Locked = True

or

Enabled = False
Locked = True

will keep the Control from being changed without greying out the Control and Label.

Linq ;0)>
Another option is to disconnect the label from the checkbox.
This way disabling checkbox will only gray it out, and not the label.
 
A couple of things:

Using this code only in the AfterUpdate event of the Checkbox has a problem! Once it has been Diabled, the Checkbox will be Disabled on every Record in your Form, even New Records! To avoid this problem, you need to also place this code in the Form_Current event of the Form, with a slight modification.
Code:
Private Sub Form_Current()
 If Me.ActiveControl = True Then
  Me.Dirty = False
  Me.CompletedAgrBr.SetFocus
  Me.StartedAgrBr.Enabled = False
 Else
  Me.StartedAgrBr.Enabled = True
 End If
End Sub
Another possible problem concerns what happens if the user accidentally ticks the Checkbox and realizes that they've made a mistake? They have no way to correct their error.

I usually handle this kind of thing by only Locking or Locking/Disabling the Control after the Record has been saved. This allows the user to correct their mistake at the time the data is being entered, but not at a later date. To do this you'd only place the code above in the Form_Current event.

One last thing is a matter of style, concern using the Enabled Property. With

Enabled = False

the Checkbox will now be greyed out, not a look that everyone wants. The attached Label is also greyed out, making recognition of Control's purpose difficult. Using

Locked = True

or

Enabled = False
Locked = True

will keep the Control from being changed without greying out the Control and Label.

Linq ;0)>

You've answered a question I was just about to ask, thanks again!!:D
 
Glad we could help! A good example of why
  • You should always use the 'Search' Function here, before posting a question.
  • All Original Posters should use a thread title that makes the subject of the thread evident.
Linq ;0)>
 
I also like to disconnect the label from the CheckBox (Or radio button) to prevent selecting by ticking the label.
But this is my taste of GUI.
 
I also like to disconnect the label from the CheckBox (Or radio button) to prevent selecting by ticking the label.
Just keep in mind that this is the behavior expected by experienced Access users and it is likely to 'tick' them off when it doesn't work! Especially in scenarios where speedy input is expected.

Some time ago I was helping a friend manage a huge data input project, using 50 operators for a projected 6-8 weeks, bringing client records from one newly acquired banking system into compliance with the system of the purchasing bank. Access was chosen for this one-time job because of its rapid development capability, and the help wanted ads stated "Experienced MS Access Users," but, of course, some jackass in the bank's IT department had to 'customize' the GUI to his liking! Among other things he'd (yes) removed the link between All Checkboxes and there Labels and even (gasp!) made it necessary to use a 'Save' button to commit a Record, instead of simply moving to another Record!

This was what they call a 'competitive production environment," meaning that the operators got paid according to how many files they could input each day, with bonuses going to the top few people. An hour into the first day one operator stood up and shouted "Who the $%^& wrote this POS app? Nothing works like it's supposed to!"

And sure enough it didn't! After a hurried conference the chief nabob announced that everyone would receive a bonus each day until the app was modified and, fortunately, we got the 'modifications' removed by Day 2!

The moral of the story is that you should always think carefully before purposefully changing the way Access is designed to work.

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom