Autopopulate field

SantasLittleHelper

Board Regular
Joined
Nov 25, 2016
Messages
77
Is it possible to have a field on a form automatically display the current date when a tick box is ticked?

e.g. There is a tick box to show whether someone has sent a package out to a customer. When the 'Package Sent' tick box is checked, I would like the 'Package Sent Date' to display the date in which it was ticked.
 
Last edited:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

bugmonsta

Board Regular
Joined
Dec 17, 2013
Messages
214
In my code I have kept the default names (checkbox1 and textbox1)

It will also empty the textbox should you untick the option, this is code against the tickbox

Code:
Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then
    TextBox1.Value = Format(Now, "dd/mm/yyyy")
    ElseIf CheckBox1.Value = False Then
    TextBox1.Value = ""
    End If
End Sub
 
Last edited:
Upvote 0

bugmonsta

Board Regular
Joined
Dec 17, 2013
Messages
214
Just got to a machine with Access (2010) and tried the code above, changed fieldnames slightly to match my test file and it works - woohoo!

Option Compare Database

Private Sub Field1_Click()
If Field1.Value = True Then
Text1.Value = Format(Now, "dd/mm/yyyy")
ElseIf Field1.Value = False Then
Text1.Value = ""
End If
End Sub
 
Upvote 0

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
i did think the idea was only to capture the date for the tick box, so
check if date is empty, if not exit sub as it has been previously updated
check for a tick and if it exists then add the date for now value and exit sub, therefore it should only complete once and never be changed
 
Upvote 0

Forum statistics

Threads
1,190,896
Messages
5,983,437
Members
439,843
Latest member
PlanetFitness

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top