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

Locking fields on Form using a check box

P: 4
Hello

I want to lock my form or record from editing after the user clicks a checkbox to prevent any changes to that record. I do not have any subforms. The checkbox is named Completed. Any advice? And I am using access 2003.
Sep 18 '08 #1
Share this Question
Share on Google+
6 Replies


ADezii
Expert 5K+
P: 8,619
Place the following code in the AfterUpdate() Event of the Completed Check Box:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Completed_AfterUpdate()
  2. On Error Resume Next
  3. Dim ctl As Control
  4.  
  5. For Each ctl In Me.Controls
  6.   'If Control Name is NOT "Completed" and it is Checked, Lock all other
  7.   'Controls. If it is not checked Unlock them
  8.   If ctl.Name <> "Completed" Then
  9.     ctl.Locked = Me![Completed]     'Evaluates to True/False
  10.   End If
  11. Next
  12.  
  13. End Sub
Sep 18 '08 #2

P: 4
I used the code as shown below and it did not produce any results. However it didnt give me an error which is the first time that hasnt happened since I attempted to write the code myself.


Private Sub Completed_AfterUpdate()
On Error Resume Next
Dim ctl As Control

For Each ctl In Me.Controls
'If Control Name is NOT "Completed" and it is Checked, Lock all other
'Controls. If it is not checked Unlock them
If ctl.Name <> "Completed" Then
ctl.Locked = Me![Completed] 'Evaluates to True/False
End If
Next

End Sub
Sep 18 '08 #3

P: 4
I used the code as shown below and it did not produce any results. However it didnt give me an error which is the first time that hasnt happened since I attempted to write the code myself.


Private Sub Completed_AfterUpdate()
On Error Resume Next
Dim ctl As Control

For Each ctl In Me.Controls
'If Control Name is NOT "Completed" and it is Checked, Lock all other
'Controls. If it is not checked Unlock them
If ctl.Name <> "Completed" Then
ctl.Locked = Me![Completed] 'Evaluates to True/False
End If
Next

End Sub

Place the following code in the AfterUpdate() Event of the Completed Check Box:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Completed_AfterUpdate()
  2. On Error Resume Next
  3. Dim ctl As Control
  4.  
  5. For Each ctl In Me.Controls
  6.   'If Control Name is NOT "Completed" and it is Checked, Lock all other
  7.   'Controls. If it is not checked Unlock them
  8.   If ctl.Name <> "Completed" Then
  9.     ctl.Locked = Me![Completed]     'Evaluates to True/False
  10.   End If
  11. Next
  12.  
  13. End Sub
Sep 18 '08 #4

ADezii
Expert 5K+
P: 8,619
I used the code as shown below and it did not produce any results. However it didnt give me an error which is the first time that hasnt happened since I attempted to write the code myself.


Private Sub Completed_AfterUpdate()
On Error Resume Next
Dim ctl As Control

For Each ctl In Me.Controls
'If Control Name is NOT "Completed" and it is Checked, Lock all other
'Controls. If it is not checked Unlock them
If ctl.Name <> "Completed" Then
ctl.Locked = Me![Completed] 'Evaluates to True/False
End If
Next

End Sub
Did you click on the Check Box Completed, then try to Edit a Field?
Sep 18 '08 #5

P: 4
Did you click on the Check Box Completed, then try to Edit a Field?
Yes, it works initially. I check completed. I try to enter another information in another field and it will not allow edits.

However, if I close the form and reopen it it allows me to edit the record even with completed checked.
Sep 18 '08 #6

missinglinq
Expert 2.5K+
P: 3,532
For the formatting to be persisted when moving record-to-record or when closing then re-opening the form, you have to use the Form_Current event to check whether the checkbox is ticked and then lock everything or unlock everything accordingly.

Welcome to Bytes!

Linq ;0>
Sep 18 '08 #7

Post your reply

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