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
 
S

Steven Burn

You can use either of the following;

(Date) - Will print the current date only
(Time) - Will print the current time only (hours, minutes and seconds)
(Now) - Will print both of the above

Example;

rsRecord!fldDate = (Date)

Apologies if "rsRecord!fldDate" is incorrect, I'm still learning Access
myself

--
Regards

Steven Burn
Ur I.T. Mate Group CEO
www.it-mate.co.uk
 
V

Van T. Dinh

I assume that your Report is based on a Query which has some sort of
criteria to select the required Records. In this case, you should be able
to create an Update SQL String to update the [Print Date] Field in the same
CommandButton_Click Event. The pseudo-code for the CommandButton should be
something like:


****Pseudo-code only****
Private Sub PrintReport_Click()
DoCmd.OpenReport ...
DoCmd.RunSQL "UPDATE YourTable SET [Print Date] = Date() " & _
"WHERE {same criteria as the Query / SQL for the Report}", False
End Sub
****

Add error-trapping as required. You can also use the Execute Method instead
of RunSQL Method.

Check Access VB Help on the RunSQL / OpenQuery (of the DoCmd Object) and the
Execute Method (of the Database or Connection Object).
 
C

Christie

Thanks Van! It worked!

Thanks to Steve, as well! However, I encountered the
following compile error: User-defined type not defined
and it highlighted the code "DB as DAO.Databse"

Again, thanks to both! It's now working!
Christie
-----Original Message-----
I assume that your Report is based on a Query which has some sort of
criteria to select the required Records. In this case, you should be able
to create an Update SQL String to update the [Print Date] Field in the same
CommandButton_Click Event. The pseudo-code for the CommandButton should be
something like:


****Pseudo-code only****
Private Sub PrintReport_Click()
DoCmd.OpenReport ...
DoCmd.RunSQL "UPDATE YourTable SET [Print Date] = Date() " & _
"WHERE {same criteria as the Query / SQL for the Report}", False
End Sub
****

Add error-trapping as required. You can also use the Execute Method instead
of RunSQL Method.

Check Access VB Help on the RunSQL / OpenQuery (of the DoCmd Object) and the
Execute Method (of the Database or Connection Object).

--
HTH
Van T. Dinh
MVP (Access)



Christie said:
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


.
 

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