MS Access Question: how to create a button to create a record with today's date

HIROYUKI TAMURA
HIROYUKI TAMURA used Ask the Experts™
on
I would like to create a button to create a record and input today's date on a field.
would you advise how to set a script on Macro tool?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer

Commented:
Function CreateDateRecord()
Dim rst as DAO.recordset
set rst = currentDb.OpenRecordset("TheNameOfYourTable")
with rst
.addNew
.Fields(TheField) = Date()
.Update
end with

Open in new window

Author

Commented:
Thank you, John!
I'm getting following error.
Would you advise?
snap254.png
Benjamin LuSAP/ERP Data Player

Commented:
if it's one field in your table, you can just set the default as date().
After you inserting one row, the field will get the current date as value, and you can change it.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

John TsioumprisSoftware & Systems Engineer

Commented:
Just replace with
End Sub

Open in new window

Author

Commented:
Thank you, John.
One more question.
snap255.png
John TsioumprisSoftware & Systems Engineer

Commented:
You have to put name of the table in double quotes
CurrentDb.OpenRecordset("SomeTable")

Open in new window

Author

Commented:
Thank you. It works now.
Do you know the script I can refresh this form after adding the record?
Software & Systems Engineer
Commented:
Me.Requery

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial