lock field until to field have data in them then when ticked lock the field again (1 Viewer)

rainbows

Registered User.
Local time
Today, 12:11
Joined
Apr 21, 2017
Messages
425
Code:
rivate Sub Form_Current()
Me.AllowEdits = (Nz(Me.[stock_changed], False) = False)
End Sub



this is the code that will lock the field when i tick the box , but it could be ticked early so i would like to keep it locked until the "date inspected" field has a date in it and the passed field either has ," passed", "part rejected" , or "short" then when i have selected one of them , then when i press the tick the "stock change " feild it locks it again

thanks steve

1678436403599.png
 

rainbows

Registered User.
Local time
Today, 12:11
Joined
Apr 21, 2017
Messages
425
Code:
Private Sub Form_Current()
Me.stock_changed.Enabled = False
'Me.Passed.Enabled = False
Select Case Me.Passed

Case "yes", "short", "part rejected"

Me.stock_changed.Enabled = True
End Select

Me.AllowEdits = (Nz(Me.[stock_changed], False) = False)

End Sub


i have managed to get this working but i dont know how to add the date inspected part in to code
 

bob fitz

AWF VIP
Local time
Today, 20:11
Joined
May 23, 2011
Messages
4,727
The code you posted would lock the whole record, so ALL the controls would be locked.
I would set the Locked property of the tick box to Yes.
Write a small function that returns true if either the "date" control or the "passed" control are null.
Set the locked property of the checkbox to that function in the AfterUpdate event of the "passed" control, in the AfterUpdate event of the "date" control, and in the forms OnCurrent event. The function might be:
Code:
Public Function fnSetBox() As Boolean
    If Not IsNull(Me.PassedCtrlName) And Not IsNull(Me.DateCtrlName) Then
        fnSetBox = False
    Else
        fnSetBox = True
    End If
End Function

EDIT:
AfterUpdate code for the textbox controls would something like:
Code:
Me.NameofCheckbox.Locked = fnSetBox
and in the forms OnCurrent event:
Code:
Me.NameofCheckbox.Locked =  Not fnSetBox
 
Last edited:

Minty

AWF VIP
Local time
Today, 20:11
Joined
Jul 26, 2013
Messages
10,371
Create a code module in the form that performs those checks and returns true or false and locks the check box based on the function.

Call the function in the after-update event of the check box and the current event.

edit: Bob beat me too it.
 

rainbows

Registered User.
Local time
Today, 12:11
Joined
Apr 21, 2017
Messages
425
hi bob
seems we posted at the same time , yes the whole record can be locked of as after the stock has been changed i dont want anyone changing it
steve
 

bob fitz

AWF VIP
Local time
Today, 20:11
Joined
May 23, 2011
Messages
4,727
Create a code module in the form that performs those checks and returns true or false and locks the check box based on the function.

Call the function in the after-update event of the check box and the current event.

edit: Bob beat me too it.
Haa Makes a change. I'm normally too slow to get an answer in before anybody :D
 

bob fitz

AWF VIP
Local time
Today, 20:11
Joined
May 23, 2011
Messages
4,727
hi bob
seems we posted at the same time , yes the whole record can be locked of as after the stock has been changed i dont want anyone changing it
steve
Take a look at the EDIT that I've added to my original post.
Using that code would keep the checkbox locked unless one of the other two controls were to be edited. otherwise, you would have no way to untick the box if it were ticked mistakenly. Quick fingers often make mistakes. Mine are slow and I make loads of mistakes :D
 

Users who are viewing this thread

Top Bottom