Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set the date Now() into a table 1

Status
Not open for further replies.

ahg

Technical User
Aug 21, 2002
27
CA
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.

AHG
 
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.

AHG
 
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
 
Thanks Randy - again,
Yes, I would appreciate seeing an example of the VBA coding.

AHG
 
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
 
Randy,
I ended up using VBA - and it works fine.
Many thanks for your help.

AHG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top