A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Lock form fields



 
 
Thread Tools Display Modes
  #1  
Old August 19th, 2004, 07:30 PM
Howard
external usenet poster
 
Posts: n/a
Default Lock form fields

I have a subform which allows the user to browse through
labour records for a given task (parent form). Regarding
the subform alone, is it possible to lock the fields
within the subform based on the value of a field within
the subform. For example, I have a status field on the
labour subform. If the status is set to "Work Order
Issued", that record should then be locked so the user can
no longer make changes. While scrolling through, the user
can make changes to other records with different status
values. Please let me know. Thanks!
-Howard
  #2  
Old August 19th, 2004, 07:43 PM
Sandra Daigle
external usenet poster
 
Posts: n/a
Default

There are a variety of ways to do this in a form - each one using the
Current Event of the form to check a status field or whatever field you have
that indicates whether the record is to be locked. You also need to execute
this code in the AfterUpdate event of the form to ensure that the record is
locked after the status changes. I've shown this code as event code but in
reality I would put it in separate procedures within the form's class module
and then call that procedure form both the Current Event and the AfterUpdate
event.

The easiest (though it has drawbacks) is to toggle the AllowEdits property
of the form. In the following, the record will be 'locked' when the
laborStatus="Work Order Issued". The drawback to using the AllowEdits
property of the form is that it also locks unbound controls when it is
false. This means that an unbound control used for locating a record is
locked when the rest of the form is locked. Not ideal in many cases.

Private Sub Form_Current()
Me.AllowEdits = Me.laborStatus="Work Order Issued"
End Sub

Note that the above is a shortcut for the following

Private Sub Form_Current()
if Me.laborStatus="Work Order Issued" then
me.allowedits=true
else
me.allowedits=false
end if
End Sub

The other way is to toggle the Locked property of individual controls based
on the value of InvoiceStatus. Put some keyword in the Tag property of each
control that should be conditionally locked then loop through all the
controls and toggle the locked property of the relevant controls. For
example - using the keyword "ToggleLock"

Private Sub Form_Current()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "ToggleLock" Then
ctl.Locked = Me.laborStatus="Work Order Issued"
End If
Next ctl
Set ctl = Nothing
End Sub


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Howard wrote:
I have a subform which allows the user to browse through
labour records for a given task (parent form). Regarding
the subform alone, is it possible to lock the fields
within the subform based on the value of a field within
the subform. For example, I have a status field on the
labour subform. If the status is set to "Work Order
Issued", that record should then be locked so the user can
no longer make changes. While scrolling through, the user
can make changes to other records with different status
values. Please let me know. Thanks!
-Howard



  #3  
Old August 19th, 2004, 08:10 PM
Howard
external usenet poster
 
Posts: n/a
Default

Thanks! In my case, the subform does not contain any
unbound controls so I think I'll utilize the first method
to toggle the AllowEdits property. If I have problems I'll
reply again. Thanks for everything!
-Howard

-----Original Message-----
There are a variety of ways to do this in a form - each

one using the
Current Event of the form to check a status field or

whatever field you have
that indicates whether the record is to be locked. You

also need to execute
this code in the AfterUpdate event of the form to ensure

that the record is
locked after the status changes. I've shown this code as

event code but in
reality I would put it in separate procedures within the

form's class module
and then call that procedure form both the Current Event

and the AfterUpdate
event.

The easiest (though it has drawbacks) is to toggle the

AllowEdits property
of the form. In the following, the record will

be 'locked' when the
laborStatus="Work Order Issued". The drawback to using

the AllowEdits
property of the form is that it also locks unbound

controls when it is
false. This means that an unbound control used for

locating a record is
locked when the rest of the form is locked. Not ideal in

many cases.

Private Sub Form_Current()
Me.AllowEdits = Me.laborStatus="Work Order Issued"
End Sub

Note that the above is a shortcut for the following

Private Sub Form_Current()
if Me.laborStatus="Work Order Issued" then
me.allowedits=true
else
me.allowedits=false
end if
End Sub

The other way is to toggle the Locked property of

individual controls based
on the value of InvoiceStatus. Put some keyword in the

Tag property of each
control that should be conditionally locked then loop

through all the
controls and toggle the locked property of the relevant

controls. For
example - using the keyword "ToggleLock"

Private Sub Form_Current()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "ToggleLock" Then
ctl.Locked = Me.laborStatus="Work Order Issued"
End If
Next ctl
Set ctl = Nothing
End Sub


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Howard wrote:
I have a subform which allows the user to browse through
labour records for a given task (parent form). Regarding
the subform alone, is it possible to lock the fields
within the subform based on the value of a field within
the subform. For example, I have a status field on the
labour subform. If the status is set to "Work Order
Issued", that record should then be locked so the user

can
no longer make changes. While scrolling through, the

user
can make changes to other records with different status
values. Please let me know. Thanks!
-Howard



.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
dlookup miaplacidus Using Forms 9 August 5th, 2004 09:16 PM
Passing value to modal child form in MS Access using VBA? Grahammer Using Forms 6 July 4th, 2004 11:53 PM
synchronizing form and list box Deb Smith Using Forms 8 June 21st, 2004 08:15 PM
form fields showing "form text" instead of values Arget New Users 2 June 9th, 2004 12:04 AM
Can merge fields be entered into text form fields? Walt Mailmerge 5 May 18th, 2004 10:16 PM


All times are GMT +1. The time now is 02:52 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.