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

Lock fields based on status change

i have a form that captures data but once a specific status is selected it can no longer be changed (status 3 or 6),
then if status = 5 it locks specific fields on the form but leaves a few fields still open.
else all fields are available.
I have some VB knowledge but not much.
I'm hoping i don't have to setfocus on each field then change the property since there are many. Then is the status changes back from 5 to 4 have to undo the same way...
Here's what i have so far:
Private Sub Status_Change()

If Status.Value = 3 Or Status.Value = 6 Then

MsgBox "You cannot change the status of this NCR Case, please see a CAPA administrator."

Else

If Status.Value = 5 Then
Jun 8 '12 #1
2 2427
Mihail
759 512MB
First of all, Welcome to the forum !

Second:
In a form you have not fields.
Only the tables and the queries have fields.
A form have only controls that can be (or not) bound to a field.

Is not necessary to set focus to each control but is necessary to set, for each control, it's locked property as you need based on the status.

Use the tag property for each control to store the status when control is locked (or when is not locked).

In the bellow code I use the tag property to store the statuses when the control is locked (see also, the attachment):
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cmdStatus1_Click()
  5.     Call SetLock(1)
  6. End Sub
  7.  
  8. Private Sub cmdStatus2_Click()
  9.     Call SetLock(2)
  10. End Sub
  11.  
  12. Private Sub cmdStatus3_Click()
  13.     Call SetLock(3)
  14. End Sub
  15.  
  16. Private Sub cmdStatus4_Click()
  17.     Call SetLock(4)
  18. End Sub
  19.  
  20. Private Sub SetLock(Status As Long)
  21. Dim ctl As Control, i As Long, ArrayStatus
  22. On Error Resume Next
  23.     For Each ctl In Me.Controls
  24.         If ctl.Tag <> "" Then 'This control is afected by status
  25.             ctl.Locked = False 'Now, the control is, no more, locked
  26.             ctl.Value = "You can change me. Try !"
  27.             ArrayStatus = Split(ctl.Tag, ",")
  28.             For i = 0 To UBound(ArrayStatus)
  29.                 If ArrayStatus(i) = Status Then 'The Status "say" that this control must be locked
  30.                     ctl.Locked = True
  31.                     ctl = "Can't change me. Try !"
  32.             Exit For
  33.                 End If
  34.             Next i
  35.         End If
  36.     Next ctl
  37. End Sub
Attached Files
File Type: zip LockControls.zip (37.4 KB, 101 views)
Jun 9 '12 #2
ADezii
8,834 Expert 8TB
A Variation along the same lines, with the Tag Property of 'Involved' Controls = 'Lock':
Expand|Select|Wrap|Line Numbers
  1. Private Sub Status_AfterUpdate()
  2. On Error Resume Next
  3. Dim ctl As Control
  4.  
  5. With Me
  6.   If IsNull(![Status]) Then
  7.     Exit Sub
  8.   Else
  9.     For Each ctl In .Controls
  10.       If ctl.Tag = "Lock" Then
  11.         ctl.Locked = (![Status] = 3 Or ![Status] = 6)
  12.       End If
  13.     Next
  14.   End If
  15. End With
  16. End Sub
Jun 9 '12 #3

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

Similar topics

2
by: Fred Prose | last post by:
Prio to installing FP3 for 8.1 on AIX 4.3 the command LIST APPLICATIONS SHOW DETAIL used to display a timestamp in the "Status Change Time" Column. Since FP3, I get a "Not Collected". As far as I...
4
by: Vladislav Moltchanov | last post by:
I am trying to find a simple solution for the porblem of error checking in a project, where at several sites data are entered using MS Access modules(developed and sent out from the data center...
2
by: adri4n | last post by:
as wat ive mentioned in the title.. im would like to know whether the a particular record/table is being locked in my program. some of the methods which i would like to develop are as below: ...
1
by: Andrew Savige | last post by:
Python beginner here. For a string 'ABBBCC', I want to produce a list . That is, break the string into pieces based on change of character. What's the best way to do this in Python? Using...
3
by: plaguna | last post by:
I'm trying to Count data in a Query Combining two different fields based on the "Date" the product was sold, and for some reason I get a wrong data. When I use only this expression, It works fine:...
11
by: angelicdevil | last post by:
ok this is wat i was trying to do...i have a list field with options A,B,P now i want the second list field to show data list by getting them from database based on the selection made in listbox1. ...
2
by: rywags11 | last post by:
Hello, Can anyone help me figure out how to show/hide fields based on information entered in other fields in a form in Access 2007? What I'm looking to do is: When a selection from a drop down is...
3
by: Miranda Truehill | last post by:
I'm very new to programming and although I've seen a similar post that addressed this in part, I am unsure how exactly to go about this. I know I can utilize the DateAdd function but don't know...
7
greeni91
by: greeni91 | last post by:
Hi There, I am making a database that is for a Maintenance Schedule. I am having a problem when it comes to locking the fields I don't need to see at this time. I have a main date at the top of...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.