Need Help with Simple VB Command

C

Christie

I need the VB command that will update a field to the
current date in multiple records. May I elaborate?

I have a form that's record source is a query that
displays all records with a null date in a particular
field- "Print Date". On this form, I have a command
button that prints a report for all these records that
have a null date in that field. I would like the command
button to auto-populate today's date in that field once
it prints the report.

I could add another command button to run an update
query, but I don't want the user to have another step in
this printing process.

Can you help? Thank you in advance.
Christie
 
F

Fredg

Christie,

I would strongly suggest you re-think how you wish to go about this.
The fact that you have sent the report to the printer does
NOT guarantee that it has been successfully printed.
Printers do run out of paper, ink, energy. etc., and the fact
that you think it was printed, well, 'it ain't necessarily so'.

To Update all the records in the table that have are Null in [Print Date]:
Place this code in the click event of a command button.

CurrentDb.Execute "Update YourTable Set YourTable.[Print Date] = Date()
Where YourTable.[Print Date] Is Null;",dbFailOnError

Change the table and field name to whatever your actual table and field
names are.
 
A

Ashby

Christie,

Your idea of using an update query is a good one. It does
not have to be another step for your users. You could
immediately after the command to print put this code.

DoCmd.SetWarnings False
DoCmd.OpenQuery "YourQueryName"
DoCmd.SetWarnings True

This will temporarily turn off the messages you would get
with an update query and then turn the messages back on.

**In your update query the "UPDATE TO" row for the Print
Date field would be =Date()

The users will never know that the query ran.
 

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