How to update the Date / Time field with the current date

I am using the following code to update the datetime field in a linked SQL table with the current date and time. However, the entered date is 12/29/1899. I don’t understand what I am missing here. Any ideas?

CurrentDb.Execute "UPDATE dbo_PAYMENT SET PAYMENT_CC_DATE_PROCESSED=#" & Now & "# AND PAYMENT_CC_EMPLOYEE_ID = 0 WHERE PAYMENT_ID=" & Me.PAYMENT_ID

+3
source share
2 answers

Here it is! Thanks a lot @Gord Thompson!

@mntyguy Aha, I see a syntax error. If you want to update multiple fields, you need to use SET Field1 = value1, Field2 = value2, not SET Field1 = value1 AND Field2 = value2

+1
source

If you use the built-in SQL Access function Now(), you do not need to put hash marks ( #) in it. (They should only limit the date literal, not the date function.) Try

... SET PAYMENT_CC_DATE_PROCESSED=Now() ...

, ,

... SET PAYMENT_CC_DATE_PROCESSED=Date() ...

, ,

... SET Field1=value1, Field2=value2 ...

not

... SET Field1=value1 AND Field2=value2 ...
+4

All Articles