Copilot for Microsoft 365 Tech Accelerator
Feb 28 2024 07:00 AM - Feb 29 2024 10:30 AM (PST)
Microsoft Tech Community

Time Card , Disabling Control once data is entered

Copper Contributor
Dear Sirs,
I am doing a dB in MS Access, the purpose of it is to record times of employee (something on the lines of Time Card)..
I have TimeIn, TimeOut and Lunchtime in and Lunchtime Out
And some employee info to go with..
I have 4 buttons for each timing, i.e. when I press button current time is passed to the time boxes (fields) the code on click of button is as under:
Me.timein = now()
Now, the problem I am facing here is I am trying to lock the field after the value is passed to it, in this case on click of button. I have tried the following code on afterupdate property of field and I also put the same code oncurrent property of form, but it doesn't work...

Private Sub Form_Current()
If Len(Me.[timTimeIn] & " ") > 0 Then
Me.[timTimeIn].Enabled = False
Me.[timTimeIn].Locked = True
Else
Me.[timTimeIn].Enabled = True
Me.[timTimeIn].Locked = False
End If

End Sub


Private Sub timTimeIn_AfterUpdate()
If Len(Me.[timTimeIn] & " ") > 0 Then
Me.[timTimeIn].Enabled = False
Me.[timTimeIn].Locked = True
Else
Me.[timTimeIn].Enabled = True
Me.[timTimeIn].Locked = False
End If
End Sub

And I am using following codes on click of buttons to pass current times

Private Sub cmdTimeIn_Click()
Me.timTimeIn = Now()

End Sub

Private Sub cmdTimeInLunch_Click()
Me.timTimeOutLunch = Now()
End Sub

Private Sub cmdTimeOutLunch_Click()
Me.timTimeInLunch = Now()
End Sub

Private Sub cmdTimeOutShift_Click()
Me.timTimeOut = Now()

End Sub

I have attached an image of my form, hope it is attached properly.
Please help.

Regards.
0 Replies