• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 453
  • Last Modified:

date field on a form

Experts, I have a button on a form and after I press this button I would like a field on the form to populate with the date I pressed the button.  I would not be using the field anywhere else in the db except on the form.  Each time I open the form, I would like the field to appear with the date.  Not sure if I could do this with an unbound field.   Thank you
2 Solutions
The code would be

Me.txtbox = date()

If you want that recorded date to persist you would need a bound field to store it.
You could create a table called tbl_Variables that contains a single record of variables you'd like to store.  In this case add a field with a Date data type and call it something like LastRunDt.

Then in the OnClick event for the button add something like:
Me.NameOfTextbox = Date
Currentdb.Execute "Update tbl_Variables Set LastRunDt=Date()", dbFailOnError

Open in new window

Then in your form's OnLoad event, add:
Me.NameOfTextbox = DLookup("LastRunDt","tbl_Variables")

Open in new window

NorieData ProcessorCommented:
If you want the field to have the date when the form opens set it's Default Value to =Date().
When you press this button does it update any table with today's date?  If so, and nothing else updates that table with another date, you could just use a DMax of the date field in that table instead of creating a Variables table like I suggested earlier.
pdvsaProject financeAuthor Commented:
The DMax function is what I ended up using.  I could have added a field to my table to store the date but I think DMax might be a better for me.  

I added a field [DateOfImport] to the table that contains the imported data and used an update qry to update it to the date of the import (date I pushed the button).

thank you.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now