如何用当前日期更新访问日期/时间字段

时间:2022-04-10 21:53:50

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

我正在使用以下代码更新链接的SQL表中的日期和时间字段。然而,get的输入日期是12/29/1899。我不明白我错过了什么。什么好主意吗?

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

CurrentDb。执行“UPDATE dbo_PAYMENT SET payment_cc_date_processing =#”& Now &“#”和“PAYMENT_CC_EMPLOYEE_ID = 0,其中PAYMENT_ID=”& Me.PAYMENT_ID

2 个解决方案

#1


4  

If you use Access SQL's built-in Now() function then you don't need to put hash marks (#) around it. (They are only required to delimit a date literal, not a date function.) Try

如果您使用Access SQL的内置Now()函数,那么您不需要在它周围加上散列标记(#)。(它们只需要分隔日期文字,而不是日期函数。)试一试

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

or, if the time component is not needed you can use

或者,如果不需要time组件,可以使用

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

Also, if you want to update multiple fields you need to use

此外,如果您希望更新需要使用的多个字段

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

not

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

#2


1  

This is it! Thanks so much @Gord Thompson!

这是它!非常感谢@Gord Thompson!

@mntyguy Aha, I see the 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

@mntyguy啊哈,我看到语法错误了。如果想要更新多个字段,需要使用SET Field1=value1、Field2=value2、而不是SET Field1=value1和Field2=value2

#1


4  

If you use Access SQL's built-in Now() function then you don't need to put hash marks (#) around it. (They are only required to delimit a date literal, not a date function.) Try

如果您使用Access SQL的内置Now()函数,那么您不需要在它周围加上散列标记(#)。(它们只需要分隔日期文字,而不是日期函数。)试一试

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

or, if the time component is not needed you can use

或者,如果不需要time组件,可以使用

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

Also, if you want to update multiple fields you need to use

此外,如果您希望更新需要使用的多个字段

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

not

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

#2


1  

This is it! Thanks so much @Gord Thompson!

这是它!非常感谢@Gord Thompson!

@mntyguy Aha, I see the 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

@mntyguy啊哈,我看到语法错误了。如果想要更新多个字段,需要使用SET Field1=value1、Field2=value2、而不是SET Field1=value1和Field2=value2