I'm trying to update a database field to the current time, but can't pass "now()". I get the following error:
'`now`' is not a recognized built-in function name.
The method I'm using to query the database is as follows:
Public Sub main()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
cnn.Open "ConnectionName"
rst.ActiveConnection 开发者_运维百科= cnn
rst.CursorLocation = adUseServer
rst.Source = "Update Table ..."
rst.Open
Set rst = Nothing
Set cnn = Nothing
End Sub
Now()
is a VBA function. What you want to do is use the equivalent SQL function, but that depends on the database that you're connecting to.
If it's SQL Server you're connecting to, use GETDATE()
(for local times) or GETUTCDATE()
(for UTC times).
Try getdate() function or CURRENT_TIMESTAMP
精彩评论