Link to home
Start Free TrialLog in
Avatar of c9k9h
c9k9h

asked on

Access: Open a report from a form; check it; if okay then email it.

I read lots of threads around emails but couldn't get where I wanted on this.  I have a form, it has a filter that opens a report for the individual I want to see stats on.  Once its opened and I agree with the numbers, I would like to click a button to email it.  I have email addresses in a table.  I can put another button on the form to email the report.  I only want the one that is opened to go.  Does this make sense?  I appreciate help!  Thanks.
Avatar of borki
borki
Flag of Australia image

Have you decided on a mechanism to send e-mails? Access has not got native support. There are plenty of 3rd party activeX controls avaialble. I like the free one from Dimac.Net. They provide some sample code in VBA how to e-mail.

You then need to save the report in an emailable format, eg PDF or RTF and send it as an attachment.
Avatar of c9k9h
c9k9h

ASKER

Actually, I'd like to use the DoCmd.SendObject method and send it as a .rtf  It's not beautiful but it gets the point out there.  We are going to the web fairly soon and I just need to fill a temporary need for some anxious customers and it will be nice to have it to fall back on for ad hoc requests, etc.  The part I'm stuck on is when I have the form open, and then click to open the report - I have that filtered so it opens the one I need - How do I filter on the email to get it to send the report that is open?
I have this function right now, but it loops through the email table and sends to all the email addresses.  Somehow I need to have it only look at the email address that matches the ISBN number on the open report.

Public Function EmailStatements() As String
    Dim db As DAO.Database
    Dim rec As DAO.Recordset
    Set db = CurrentDb()
    Set rec = db.OpenRecordset("tbl_EmailRoyalties", dbOpenDynaset)
   
On Error GoTo ErrorHandling_Resume
With rec
    .MoveFirst
        Do While Not .EOF
                DoCmd.SendObject acReport, rec!ReportName, acFormatRTF, rec!Email, "", "", rec!MonthYr, "rec!Message", False, """"""
            rec.MoveNext
        Loop
End With
MsgBox "Files have been sent!", _
vbOKOnly + vbExclamation, "Success!"
   
ErrorHandling_Resume:
    Resume Next
   
End Function
 Sample from "tbl_EmailRoyalties"
Email                                                          ISBN
GHull@GEAPubGroup.com                 9781606930410  
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of c9k9h

ASKER

Thanks Jeff, I'll check this out when I get home from work tonight.
Avatar of c9k9h

ASKER

Wow!  Looks like it took me 8 days to get home!  Sorry about that.  I could not get it to work.  
If I put the command line directly on the button, I get a runtime error '424', Object required.  If I put it in the function that I have above, I get a compile error:  Invalid use of 'Me' keyword.  I have a feeling I'm missing something simple.
 
You probably have a missing reference. Go to the VBA window and check Tools > Reference. If it lists a missing reference, you must look for file in the list or add a new reference.

HTH
Avatar of c9k9h

ASKER

I don't think it's missing a reference.  I have the following selected:
Visual Basic for Applications; Miscroft Access 11.0 Object Library; OLE Automation; Microsft ActvieX Data Objects 2.1 Library; Microsoft Calendar Control 11.0; Microsoft ADO Ext 2.8 for DDL and Security; and Microsoft DAO 3.6 Object Library.
Can you post a sample so we don't have to guess anymore?
Avatar of c9k9h

ASKER

Jeff . . . this got away from me.  I apologize for keeping it open so long.  I can't get back to it - way too much stuff going on.  However, you have some good suggestions for others to try if they have a similar issue l and it may very well work for them - so I would like to assign you the points and keep this in the knowledge db.
Avatar of c9k9h

ASKER

I believe all of these will work in the right scenario.  I honestly did not have the time to get back to this (I ended up sending emails from the web) - but again, this is some good suggestions for others to see around emailing.  So I'm leaving rather than remove the question.  Thank you very much for you work here.