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
249 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Omit After Update event 5 46
Balance After Payment 12 62
Handle Apostrophes in VBA SQL - Part 2 10 48
ms/access follow hiperlink and generate image 5 16
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

739 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