Update table with date and number

J

JB

I'm trying to update a table with the current date and the current user ID
but I keep getting a syntax error. Could somebody check my code and tell me
what I'm doing wrong?

Dim strUserID As Integer

strUserID = DLookup("UserID", "q_GetUser")

CurrentDb.Execute "UPDATE (pt_PurchaseOrders) SET
pt_PurchaseOrders.CancelledDate = Date(), pt_PurchaseOrders.CancelledBy =
strUserID WHERE pt_PurchaseOrders.PONumber = " & Me.PONumber
 
D

Daryl S

JB -

Two things - you want the RunSQL statement (not the Execute), and also the
strUserID needs to have single quotes put around the text as a delimeter.
Try this:

DoCmd.RunSQL "UPDATE (pt_PurchaseOrders) SET pt_PurchaseOrders.CancelledDate
= Date(), pt_PurchaseOrders.CancelledBy = '" & strUserID & "' WHERE
pt_PurchaseOrders.PONumber = " & Me.PONumber

If the PONumber is a text field, it would need the delimeters also.
 
J

JB

Thanks Daryl.

It works perfectly now.


Daryl S said:
JB -

Two things - you want the RunSQL statement (not the Execute), and also the
strUserID needs to have single quotes put around the text as a delimeter.
Try this:

DoCmd.RunSQL "UPDATE (pt_PurchaseOrders) SET pt_PurchaseOrders.CancelledDate
= Date(), pt_PurchaseOrders.CancelledBy = '" & strUserID & "' WHERE
pt_PurchaseOrders.PONumber = " & Me.PONumber

If the PONumber is a text field, it would need the delimeters also.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top