how to unlock one field on a locked subform

Local time
Today, 14:28
Joined
Apr 25, 2019
Messages
69
I have a main form that locks the one subform after 12 hours. I need to be able to keep just one field on the subform unlocked at all times. There are too many fields on the subform to lock and unlock each one indivdually. Right now I just lock the whole subform and unlock the whole subform with a single vba code. But i cant seem to unlock the single field on the subform, once the whole subform is locked. any ideas?
 
Simply select all the controls except the one in design view then tag them "Lock"
Now instead of locking the form run this code.
Code:
Public Sub lockControls()
  Dim ctrl As Access.Control
  For Each ctrl In Me.Controls
    If ctrl.Tag = "Lock" Then
      ctrl.Locked = True
    End If
Next ctrl
End Sub
 
you can also Keep your subform Locked set to Yes.
then on design view of your form/subform, click on the Textbox on the subform and add this to the following events:
lock.png


Now, create LockMe function on the subform.
you substitute your Main form name to MainFormNameHere and your subform name to SubformNameHere

Code:
Public Function LockMe(ByVal tfLock As Boolean)
        Forms!MainFormNameHere!SubformNameHere.Locked = tfLock
End Function

see this demo. the textbox "Last Name" on the subform is Unlocked.
 

Attachments

you can also Keep your subform Locked set to Yes.
then on design view of your form/subform, click on the Textbox on the subform and add this to the following events:
View attachment 104840

Now, create LockMe function on the subform.
you substitute your Main form name to MainFormNameHere and your subform name to SubformNameHere

Code:
Public Function LockMe(ByVal tfLock As Boolean)
        Forms!MainFormNameHere!SubformNameHere.Locked = tfLock
End Function

see this demo. the textbox "Last Name" on the subform is Unlocked.
OK, I am confused by that? :(
Surely if you are unlocking when the control gets the focus/clicked, then you may as well leave it unlocked?
 
then you may as well leave it unlocked?
you can't Selectively unlocked a control when the Form itself is locked.

it is actually Unlocking the Form when the "last name" get focus.
and Lock it again when the focus shift to another control.
 
you can't Selectively unlocked a control when the Form itself is locked.

it is actually Unlocking the Form when the "last name" get focus.
and Lock it again when the focus shift to another control.
Yes, I realise that, but surely just locking all controls after 12 hours, simple loop?, then unlock that one control, is a one time operation?
 
locking all controls after 12 hours, simple loop?,
you adapt whatever will make you happy.
i am not forcing anything to you.
 
The other things is don't worry about setting a few controls causing delays. It's infinitesimally quick. Not quite that quick, but you are talking a handful of instructions out of potentially MIPS, so it's as good as instant. It's writing and managing it that takes time, but you can't really avoid that to get the right user experience, and you should only need to do the set up once.
 

Users who are viewing this thread

Back
Top Bottom