By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,729 Members | 1,398 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,729 IT Pros & Developers. It's quick & easy.

Before event for checkbox

P: 10
Hi there,

My level of VBA coding is not great and I can get by with docmd. functions but I want to have a checkbox which if it is not ticked means that subsequent data after it cannot be entered (so the text boxes are greyed out) but when the checkbox is clicked the text boxes become active and allow data entry. Can someone help me?!
Mar 5 '14 #1

✓ answered by NeoPa

Very much along the lines Seth has already illustrated, but changing the code structure slightly to accommodate being used from more than one event procedure, I'd suggest :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     Call ChangesAllowed()
  3. End Sub
  4.  
  5. Private Sub chkAllowChanges_AfterUpdate()
  6.     Call ChangesAllowed()
  7. End Sub
  8.  
  9. Private Sub ChangesAllowed()
  10.     With Me
  11.         .txtMyControl.Enabled = .chkAllowChanges
  12.         .txtMyControl2.Enabled = .chkAllowChanges
  13.         ...
  14.     End With
  15. End Sub
The first event procedure is so that this can be remembered for pre-existing records as well as the one you're working on currently.

Share this Question
Share on Google+
4 Replies


Seth Schrock
Expert 2.5K+
P: 2,951
I'll give you an example with one control and you can then copy the idea for your other controls as well. Lets say that your checkbox is named chkAllowChanges and that one of your textboxes that you want grayed out is named txtMyControl. Then, in the checkbox's After_Update event, put this:
Expand|Select|Wrap|Line Numbers
  1. Me.txtMyControl.Enabled = Me.chkAllowChanges
Just change the control names to fit yours and put a line for each control that need this behavior.
Mar 5 '14 #2

NeoPa
Expert Mod 15k+
P: 31,769
Very much along the lines Seth has already illustrated, but changing the code structure slightly to accommodate being used from more than one event procedure, I'd suggest :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     Call ChangesAllowed()
  3. End Sub
  4.  
  5. Private Sub chkAllowChanges_AfterUpdate()
  6.     Call ChangesAllowed()
  7. End Sub
  8.  
  9. Private Sub ChangesAllowed()
  10.     With Me
  11.         .txtMyControl.Enabled = .chkAllowChanges
  12.         .txtMyControl2.Enabled = .chkAllowChanges
  13.         ...
  14.     End With
  15. End Sub
The first event procedure is so that this can be remembered for pre-existing records as well as the one you're working on currently.
Mar 5 '14 #3

P: 10
Thanks! I am a bit new to Access so tried the first method first then used the second one as well when I had more confidence! Thanks to both!
Mar 12 '14 #4

NeoPa
Expert Mod 15k+
P: 31,769
Good for you. I'm pleased to hear you're benefitting from the forum and learning as you go :-)
Mar 13 '14 #5

Post your reply

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