I have a lookup table which contains one date field. I want to update (change) this date to Now() when I click a button on a form.
Can anyone please show me the code required to update this date field?
Many thanks in anticipation.
Hi,
If the field is on the form, you can use some simple code to update it to the current time. If it is not on the form, you can add it, then set the visible property to false. Here is the code you should use to update the date/time (presuming that the field is called "Updated_date":
Me![Updated_date] = Now HTH,
Randy Smith
California Teachers Association
Thanks Randy, but the field is not on the form at the moment. No reason why it shouldn't be I suppose in which case it is probably a simpler approach. I will check it out and get back to you.
Thanks for your assistance.
Hi,
You can update a field that is not on the form, but it requires some SQL programming in VBA. It is a bit more complicated than it should be, that is why I recommend to people that they put the field on the form, and then hide it using the Visible=False property.
if you want to see a sample of the VBA coding to do an SQL update, just let me know. HTH,
Randy Smith
California Teachers Association
Hi,
YOu can try something like this (presuming the table is called "XYZ", the field is called "fldDate" and the record being updated has a unique key named "CustId" and a value of "12345"
Dim db As Database
Set db = CurrentDb()
db.Execute "UPDATE XYZ SET fldDate = now WHERE CustId = '12345'"
Notice that we are assuming that the CustId field is string, which then requires single quotes around the value. HTH,
Randy Smith
California Teachers Association
Actually, you can update a field that is not on the form without using SQL, as long as it's in the form's recordset.
Access creates a form property for every field in its recordset, when the recordset is opened. The property has the same name as the field.
So, if a form's Record Source is "Query1" and Query1 has columns "ID", "Customer", and "DateUpdated", but DateUpdated isn't on the form, the following statement will assign the current date and time to DateUpdated:
Me.DateUpdated = Now Rick Sprague
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.