PDA

View Full Version : Data Entry Form data to emailed report



Scooter172
10-20-2011, 10:23 PM
I have a Data Entry Form that after filling in and hitting the New Record Button I want a macro or code to Print the data that was entered into that entry only in a report (PDF) to be emailed to an email group. Example... Employee calls in sick and after the entry the report is mailed to managment group as well as other staff.

hansup
10-21-2011, 09:28 AM
That combination of requirements is challenging. I don't see a way to do this cleanly.

A kludge approach could be adding a Yes/No field, "notice_sent", to the employee absence table with the default value as False.

The in the form's after insert event, you could use the DoCmd.SendObject Method to email your report as PDF.

http://msdn.microsoft.com/en-us/library/bb214075(office.12).aspx

You would need to base the report on a query with a WHERE clause like:

WHERE notice_sent = False

Then after the SendObject command, set notice_sent to True.

This suggestion assumes you have Access 2007 with SP1 or Access 2010. If your Access version is 2003 or earlier, there will be more hoops to jump through in order to send the report as PDF.

Scooter172
10-21-2011, 09:18 PM
the report cannot show the record as the record has not been recorded in the table until after the form is closed.

hansup
10-22-2011, 10:09 AM
That caught me by surprise. When I add a new record through a form, or edit an existing record, then attempt to navigate to a different record, that forces an implicit save of the "dirty" record. (where dirty = record with unsaved changes) The only alternative is to discard the changes to the dirty record.

So apparently I misunderstood your description. However that brings up another point ... which could be a deal breaker for your goal: I don't know how to use an unsaved record in an Access report.

HiTechCoach
10-22-2011, 09:26 PM
Your "New" command button will need to:

1) force the record to be saved.
2) Generate the report to PDF.
3) Send then emain.
4) go to the new reocrd.

To forace a record to be saved use:



Dirty = False