views:

35

answers:

2

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
+3  A: 

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

eksortso
Thanks so much, I tried out that function and it worked like a charm. I'm coming from a MySQL background and now() was a usable function. This is where my confusion came from. I will "accept" your answer as soon as the time limit is up.Happy coding :)
Soo
+2  A: 

Try getdate() function or CURRENT_TIMESTAMP

msi77
That's a good one, too. `CURRENT_TIMESTAMP` is SQL standard, and SQL Server understands it without parentheses.
eksortso