Solved

How do I run a Macro in Access 2007 each time a new record is added to the database

Posted on 2009-05-15
6
248 Views
Last Modified: 2013-11-27
Hello,

I'm in the process of designing an Access database for a reservation system.  I have a Java front end that allows data entry into the database, but would like to have a confirmation report printed each time a new record is added.  I know that one of the options when creating macros in Access is to print a report, but I'm not sure what condition to use so that the macro is run every time a new record is added.  Also, I want the report to use the most recent information in the report.  Any help would be great.

Thanks,

Raymond Northcott
0
Comment
Question by:rnorthcott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 5

Expert Comment

by:noetymology
ID: 24398923
I would create a form for only data entry. On the On Close event of the form, i would use the following code
DoCmd.Save , acForm, "frmCustomers"
DoCmd.OpenReport "rptCustomers", acViewReport, "", "", acNormal
DoCmd.PrintOut acPrintAll, , , acHigh, 1, True
DoCmd.Close acReport, "rptCustomers"
I would filter my report based on the data present on the data entry form. For eg, i entered a record for Customer No. 15, On closing the form, it is ensure that the data is saved, then report will be generated for only Customer No. 15, printed and then closed immediate, so that the user doesnt notice that it had been opened.
0
 
LVL 5

Expert Comment

by:noetymology
ID: 24398954
There could also be other  methods like having a button on the form to print the report. Instead of VBA you can also use a macro do to the same. Also instead of having to click a button , you can also put the VBA/macro in the Lost Focus event of the textbox that you would enter data to at the last. This way once the data is entered and you press tab key, the last control would lose its focus and report would be printed, however this method can have problems as if someone puts the focus and then moves out from that last text box then it would fire that VBA/macro and an incomplete report may get printed
0
 

Author Comment

by:rnorthcott
ID: 24399010
Is there a way to do this without using a form?  I'm hoping that the end user will only have to run my java front end to do the data entry, instead of a form in access.
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 5

Accepted Solution

by:
noetymology earned 125 total points
ID: 24399058
Sorry but my expertise are not with Java however i found this for you if it can help. As shown here, you can create a VB script and call it in your Java app. Replace the Excel Application with Access and call the macro created in Access that would print your report. http://www.egjug.org/call_excel_macro_from_java
0
 

Author Closing Comment

by:rnorthcott
ID: 31582063
Thank you for your efforts.
0
 
LVL 5

Expert Comment

by:noetymology
ID: 24399105
You are very welcome. Good luck!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question