473,385 Members | 1,355 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,385 software developers and data experts.

Locking Records in MS Access 2003

greeni91
I am currently producing a database to check the problems we have with parts are my work. I have set up an input form and linked tables to it. I have 6 areas on my sheet I want to lock when I click on a checkbox at the side of my form. One checkbox needs to lock three fields of information. I am currently using this code in VBA to lock the fields:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Complete1_Click()
  2.  If Me.Complete1 = True Then
  3.    Me.IFAWhat1.Enabled = False
  4.    Me.IFAWho1.Enabled = False
  5.    Me.IFAWhen1.Enabled = False
  6.  Else
  7.     Me.IFAWhat1.Enabled = True
  8.    Me.IFAWho1.Enabled = True
  9.    Me.IFAWhen1.Enabled = True
  10.  End If
  11. End Sub
  12.  
  13. Private Sub Complete1_AfterUpdate()
  14.  If Me.Complete1 = True Then
  15.    Me.IFAWhat1.Enabled = False
  16.    Me.IFAWho1.Enabled = False
  17.    Me.IFAWhen1.Enabled = False
  18.  Else
  19.    Me.IFAWhat1.Enabled = True
  20.    Me.IFAWho1.Enabled = True
  21.    Me.IFAWhen1.Enabled = True
  22.  End If
  23. End Sub
  24.  
  25. Private Sub Complete2_Click()
  26.  If Me.Complete2 = True Then
  27.    Me.IFAWhat2.Enabled = False
  28.    Me.IFAWho2.Enabled = False
  29.    Me.IFAWhen2.Enabled = False
  30.  Else
  31.    Me.IFAWhat2.Enabled = True
  32.    Me.IFAWho2.Enabled = True
  33.    Me.IFAWhen2.Enabled = True
  34.  End If
  35. End Sub
  36.  
  37. Private Sub Complete2_AfterUpdate()
  38.  If Me.Complete2 = True Then
  39.    Me.IFAWhat2.Enabled = False
  40.    Me.IFAWho2.Enabled = False
  41.    Me.IFAWhen2.Enabled = False
  42.  Else
  43.    Me.IFAWhat2.Enabled = True
  44.    Me.IFAWho2.Enabled = True
  45.    Me.IFAWhen2.Enabled = True
  46.  End If
  47. End Sub
  48.  
  49. Private Sub Complete3_Click()
  50.  If Me.Complete3 = True Then
  51.    Me.IFAWhat3.Enabled = False
  52.    Me.IFAWho3.Enabled = False
  53.    Me.IFAWhen3.Enabled = False
  54.  Else
  55.    Me.IFAWhat3.Enabled = True
  56.    Me.IFAWho3.Enabled = True
  57.    Me.IFAWhen3.Enabled = True
  58.  End If
  59. End Sub
  60.  
  61. Private Sub Complete3_AfterUpdate()
  62.  If Me.Complete3 = True Then
  63.    Me.IFAWhat3.Enabled = False
  64.    Me.IFAWho3.Enabled = False
  65.    Me.IFAWhen3.Enabled = False
  66.  Else
  67.    Me.IFAWhat3.Enabled = True
  68.    Me.IFAWho3.Enabled = True
  69.    Me.IFAWhen3.Enabled = True
  70.  End If
  71. End Sub
  72.  
  73. Private Sub Complete4_Click()
  74.  If Me.Complete4 = True Then
  75.    Me.PRAWhat1.Enabled = False
  76.    Me.PRAWho1.Enabled = False
  77.    Me.PRAWhen1.Enabled = False
  78.  Else
  79.    Me.PRAWhat1.Enabled = True
  80.    Me.PRAWho1.Enabled = True
  81.    Me.PRAWhen1.Enabled = True
  82.  End If
  83. End Sub
  84.  
  85. Private Sub Complete4_AfterUpdate()
  86.  If Me.Complete4 = True Then
  87.    Me.PRAWhat1.Enabled = False
  88.    Me.PRAWho1.Enabled = False
  89.    Me.PRAWhen1.Enabled = False
  90.  Else
  91.    Me.PRAWhat1.Enabled = True
  92.    Me.PRAWho1.Enabled = True
  93.    Me.PRAWhen1.Enabled = True
  94.  End If
  95. End Sub
  96.  
  97. Private Sub Complete5_Click()
  98.  If Me.Complete5 = True Then
  99.    Me.PRAWhat2.Enabled = False
  100.    Me.PRAWho2.Enabled = False
  101.    Me.PRAWhen2.Enabled = False
  102.  Else
  103.    Me.PRAWhat2.Enabled = True
  104.    Me.PRAWho2.Enabled = True
  105.    Me.PRAWhen2.Enabled = True
  106.  End If
  107. End Sub
  108.  
  109. Private Sub Complete5_AfterUpdate()
  110.  If Me.Complete5 = True Then
  111.    Me.PRAWhat2.Enabled = False
  112.    Me.PRAWho2.Enabled = False
  113.    Me.PRAWhen2.Enabled = False
  114.  Else
  115.    Me.PRAWhat2.Enabled = True
  116.    Me.PRAWho2.Enabled = True
  117.    Me.PRAWhen2.Enabled = True
  118.  End If
  119. End Sub
  120.  
  121. Private Sub Complete6_Click()
  122.  If Me.Complete6 = True Then
  123.    Me.PRAWhat3.Enabled = False
  124.    Me.PRAWho3.Enabled = False
  125.    Me.PRAWhen3.Enabled = False
  126.  Else
  127.    Me.PRAWhat3.Enabled = True
  128.    Me.PRAWho3.Enabled = True
  129.    Me.PRAWhen3.Enabled = True
  130.  End If
  131. End Sub
  132.  
  133. Private Sub Complete6_AfterUpdate()
  134.  If Me.Complete6 = True Then
  135.    Me.PRAWhat3.Enabled = False
  136.    Me.PRAWho3.Enabled = False
  137.    Me.PRAWhen3.Enabled = False
  138.  Else
  139.    Me.PRAWhat3.Enabled = True
  140.    Me.PRAWho3.Enabled = True
  141.    Me.PRAWhen3.Enabled = True
  142.  End If
  143. End Sub
The problem I am having is that when I click on the checkbox it locks the fields on ALL records, I am looking for a way to fix this code to be record specific


P.S. I have a field at the top of the form called "ProblemNo", I was wondering if this could be used as it is connected to my main table and is the "Serial Number" of the problem I am currently looking at...

Thanks in Advance

/Sandy
Nov 26 '09 #1

✓ answered by missinglinq

First off, there is no need to have the same code for each checkbox appear in the OnClick event and the AfterUpdate event. One or the other will do!

Secondly, because you're apparently (from your description) doing this on a Continuous or Datasheet View Form, you need to use, for each appropriate control

Me.PRAWhat3.Enabled = False
Me.PRAWhat3.Locked = True


or

Me.PRAWhat3.Enabled = True
Me.PRAWhat3.Locked = False


in order for the formatting not to be obvious on all records, as setting the Enabled Property alone will. Using this combination "locks" the control, but doesn't "gray" it out.

Finally, in order for the formatting, i.e. the "locking" of the record to be record-specific, you need to include this code in the Form_Current event.

In this way, if you move to a record, the corresponding fields will be "locked" or not depending on its checkbox.

Welcome to Bytes!

Linq ;0)>

4 2109
missinglinq
3,532 Expert 2GB
First off, there is no need to have the same code for each checkbox appear in the OnClick event and the AfterUpdate event. One or the other will do!

Secondly, because you're apparently (from your description) doing this on a Continuous or Datasheet View Form, you need to use, for each appropriate control

Me.PRAWhat3.Enabled = False
Me.PRAWhat3.Locked = True


or

Me.PRAWhat3.Enabled = True
Me.PRAWhat3.Locked = False


in order for the formatting not to be obvious on all records, as setting the Enabled Property alone will. Using this combination "locks" the control, but doesn't "gray" it out.

Finally, in order for the formatting, i.e. the "locking" of the record to be record-specific, you need to include this code in the Form_Current event.

In this way, if you move to a record, the corresponding fields will be "locked" or not depending on its checkbox.

Welcome to Bytes!

Linq ;0)>
Nov 26 '09 #2
NeoPa
32,556 Expert Mod 16PB
As Linq implied, the controls' attributes don't change per record, they change globally. That is to say there is only one control (for each) whose attributes are the same wherever it is seen on the form (See Why Values in Unbound Form Controls do not Persist). That is why you should follow Linq's advice about running the code in the Form_Current() event procedure too.

Because of this it is a good idea to have the code itself in separate procedures, and invoke them from the various event procedures where they are appropriate.

I would also consider shortening the code as there is little need for so many lines when it can be put more succinctly, without any loss of clarity (readability). As an example I'll post the code for one control :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Call Handle1(Me.Complete1)
  3.   Call Handle2(Me.Complete2)
  4.   ...
  5. End Sub
  6.  
  7. Private Sub Complete1_AfterUpdate()
  8.   Call Handle1(Me.Complete1)
  9. End Sub
  10.  
  11. Private Sub Complete2_AfterUpdate()
  12.   Call Handle1(Me.Complete2)
  13. End Sub
  14.  
  15. ...
  16.  
  17. Private Sub Handle1(ByVal blnComplete As Boolean)
  18.   Me.IFAWhat1.Enabled = (blnComplete = False)
  19.   Me.IFAWho1.Enabled = (blnComplete = False)
  20.   Me.IFAWhen1.Enabled = (blnComplete = False)
  21. End Sub
  22.  
  23. Private Sub Handle2(ByVal blnComplete As Boolean)
  24.   Me.IFAWhat2.Enabled = (blnComplete = False)
  25.   Me.IFAWho2.Enabled = (blnComplete = False)
  26.   Me.IFAWhen2.Enabled = (blnComplete = False)
  27. End Sub
  28.  
  29. ...
Nov 29 '09 #3
Thanks very much to both of you...This method works a treat and my database is now fully funtioning... Can't thenk you enough.

/Sandy
Nov 30 '09 #4
NeoPa
32,556 Expert Mod 16PB
Always a pleasure Sandy :)

I'll set the Best Answer for you.
Nov 30 '09 #5

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

Similar topics

3
by: Ryan | last post by:
I have a problem with record locking / blocking within an application. The app is quite straight forward. Written in Delphi 5 using BDE to access a SQL 7 database (Win2K server). Every so often...
0
by: ethanj /personal/ | last post by:
We are using Access 2000 database, with the following settings. Tool > Options > Advance > Default Record Locking = Edited Record Open databases using record level locking = True Form...
6
by: MS | last post by:
Access 97 here. I want a simple way to "lock" certain records on a form. Some records remain "live" until all data is available which happens over time. When all the fields are complete, I want...
0
by: brijeshmathew | last post by:
Hi I use Visual Basic 6, Service Pack 6, Microsoft ActiveX Data Objects 2.8 Library(msado15.dll) and access 2000 database using JET 4 OLE. I have an application that adds records simultaneously...
2
by: pj | last post by:
We are experiencing record locking errors which don't make sense. O/S :Windows 2003 Server running Terminal Services Access 2003 SP1 Front end copied to each user folder. 4 users adding...
8
by: paulwilliamsonremove | last post by:
Hi, Using Access 2003. I am trying to delete records from one table/query ("qryHistoryPersonIDs") if they don't exist in another table ("qryDonations"). But the SQL syntax I came up with is...
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...
1
by: ABrown | last post by:
Hello, I have a 2003 database set up with about 20 users (only about 4 at a time) but I repeatedly get a problem with the records all locking. Each User is assigning billing codes to jobs so they...
0
by: tbeers | last post by:
Good afternoon. I am ready to deploy a database using access 2007. Been pretty happy with the development process. However, the application will be used over a terminal server network...windows...
3
by: kstevens | last post by:
I have turned on record locking do to the fact that we are starting to have issues with the records not being locked. I have a button on a form that changes the recordsource of the form. When i...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.