lock field until to field have data in them then when ticked lock the field again

rainbows

Registered User.
Local time
Today, 02:37
Joined
Apr 21, 2017
Messages
428
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
 
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
 
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:
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.
 
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
 
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
 
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

Back
Top Bottom