I have current code that first updates a field named Exported in a table to the current time (using the Now() function), then it opens a report based on that table with criteria of Now() for that same Exported field. My current code is:
DoCmd.RunSQL "UPDATE [Orders] SET [Orders].[Exported] = Now() WHERE ((([Orders].[Status ID])=2));"
DoCmd.OpenReport "Card Charges and Updates", acViewPreview, "", "Exported = Now()", acNormal
Sometimes everything is fine and others the report is blank. I'm assuming that it could be due to a hang in the computer making a different time being generated by the Now() function used.
Is there any way to use a variable in the criteria portion in the code to make it something like?
Dim ExportTime As Date
ExportTime = Now()
DoCmd.RunSQL "UPDATE [Orders] SET [Orders].[Exported] = ExportTime WHERE ((([Orders].[Status ID])=2));"
DoCmd.OpenReport "Card Charges and Updates", acViewPreview, "", "Exported = ExportTime", acNormal
I've tried this exact code, but it throws up errors. Is it even possible to use variables like so, and if so what would be the correct syntax? If not, does anyone have any suggetions on how to make this work?
Thanks
DoCmd.RunSQL "UPDATE [Orders] SET [Orders].[Exported] = Now() WHERE ((([Orders].[Status ID])=2));"
DoCmd.OpenReport "Card Charges and Updates", acViewPreview, "", "Exported = Now()", acNormal
Sometimes everything is fine and others the report is blank. I'm assuming that it could be due to a hang in the computer making a different time being generated by the Now() function used.
Is there any way to use a variable in the criteria portion in the code to make it something like?
Dim ExportTime As Date
ExportTime = Now()
DoCmd.RunSQL "UPDATE [Orders] SET [Orders].[Exported] = ExportTime WHERE ((([Orders].[Status ID])=2));"
DoCmd.OpenReport "Card Charges and Updates", acViewPreview, "", "Exported = ExportTime", acNormal
I've tried this exact code, but it throws up errors. Is it even possible to use variables like so, and if so what would be the correct syntax? If not, does anyone have any suggetions on how to make this work?
Thanks
Last edited: