473,378 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Locking fields on Form using a check box

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
6 7517
ADezii
8,834 Expert 8TB
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
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
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
8,834 Expert 8TB
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
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
3,532 Expert 2GB
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

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

Similar topics

2
by: vishal | last post by:
hello friends i have one php script which generates html page containing form. what i want is submit this form using php script. pls give me some idea that how can i submit form using php...
3
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers...
4
by: Chris | last post by:
Dear all, I would like to figure out a way to add controls to a form using specs stored in a table. Any assistance in fleshing this idea out would be greatly appreciated. I'm using VB6. ...
4
by: btopenworld | last post by:
I am submitting a form using an image as the link to a js file. The image calls a js function which checks fields- issuing alerts for errors - if no errors it then submits the form. I would like...
3
by: Justin Sane | last post by:
I haven't been able to select a form using getElementById. I only can select a form using the "name" property of the <form> tag. Is there another way to select a form, or is it even possible to use...
2
by: Michael Creager | last post by:
I am using VB NET 2002. How can I programmatically create a new windows form using the value of a string variable as the name of the new form? Public FrmName As String = "MDIChildFrm1" Public...
4
by: listerofsmeg01 | last post by:
I think I probably know that answer, but I will ask anyway. Is it possible to submit a form using a standard anchor link, rather than a submit button? The reason I ask is that I have a standard...
6
by: Trees | last post by:
I have a database that was created so that 4 separate shops could go in and enter pertinent information about how their shops ran throughout the day so that my boss (and theirs) could report out...
6
by: Palehorse | last post by:
I'd like to apologize upfront for me saying "I'm not a programer", I'm sure you all hear this a hundred times a day. Unfortunately, in this case, it's true. I've been working on trying to figure out...
7
by: Jane Alford | last post by:
I apologise in advance if my previous question has got itself held up in a queue, but there's been no sign of it for over 3 hours now... I have a MAJOR problem, that I'm sure has a simple...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.