Auto Date Based On Checkbox (1 Viewer)

vcarrill

Registered User.
Local time
Today, 07:16
Joined
Aug 22, 2019
Messages
60
Hello!

I have a checkbox called "Received", and a field called "Received Date". I would like the date to auto populate in the "Received Date" field upon clicking the checkbox.

I went under properties for the checkbox, event, code and entered the following:

Private Sub Received_Click()
If Received.Value Then
[Received Date] = Date
End If
End Sub

This is working great so far, but how do I get it to remove the date if I uncheck the box?

Thank you
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 06:16
Joined
Oct 29, 2018
Messages
21,357
Hi. I suggest using the AfterUpdate event. For example:
Code:
Private Sub Received_AfterUpdate()
    If Me.Received Then
        Me.[Received Date] = Date()
    Else
        Me.[Received Date] = Null
    End If
End Sub
 

Mark_

Longboard on the internet
Local time
Today, 06:16
Joined
Sep 12, 2017
Messages
2,111
If you have a date for received, why do you need a check box also? Any place you would use "If checkbox= true" you can check for a received date. This avoids redundancy of data and helps you in case someone decides to do something silly (like unsetting check boxes but not clearing dates)

You can toss in an unbound text box that sets the received date as theDBguy's posted to accomplish what you need. This could be set to "true" if there is a received date already when you load the current record even. Personally I'd simply put on a button to do the work and disable it if there is a received date. This way you don't have people receiving materials then accidentally clearing out when they were received.
 

Users who are viewing this thread

Top Bottom