Email Report (1 Viewer)

meccer

New member
Local time
Today, 18:37
Joined
Apr 13, 2011
Messages
4
Hello, I've used embedded macros to email a report;

I've got two issues:
1. I want to email 2 reports in pdf format but they only give one option, how do I do this?

2. How can I include my email signature, I've tried using the email template my signature is in html format, but nothing shows on the email.
 

smig

Registered User.
Local time
Today, 23:37
Joined
Nov 25, 2009
Messages
2,209
what version of Access ?
how do you send the emails ?
 

meccer

New member
Local time
Today, 18:37
Joined
Apr 13, 2011
Messages
4
I'm using Access 2007

I use the SendObject in in Embedded Macro.
I hope this helps.
 

smig

Registered User.
Local time
Today, 23:37
Joined
Nov 25, 2009
Messages
2,209
not using Access2007, nor SendObject so I can't help you here
sorry,
 

stopher

AWF VIP
Local time
Today, 21:37
Joined
Feb 1, 2006
Messages
2,395
If you are using Outlook then instead of using Sendobject you can use this code:

Code:
Public Sub SendEmail()

    Dim appOutLook As Object
    Dim MailOutLook As Object
        
    'create the two reports temporarily
    DoCmd.OutputTo acOutputReport, "Report1", acFormatPDF, "c:\someLocation\Report1.pdf", False
    DoCmd.OutputTo acOutputReport, "Report2", acFormatPDF, "c:\someLocation\Report2.pdf", False
    
    'assign our object references
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
        
    With MailOutLook
        'set the recipient list
        .To = "someone@somewhere.com"
        
        'set the subject
        .Subject = "My Reports"
        
        'set the body text
        .body = "Here are the reports in pdf format"
        
        'add the reports we created
        .attachments.Add "c:\someLocation\Report1.pdf"
        .attachments.Add "c:\someLocation\Report2.pdf"
        
        'send the email
        .Send
    End With
    
    'tidy up..
    
    'get rid of our object references
    Set appOutLook = Nothing
    Set MailOutLook = Nothing

    'delete our temporary files
    Kill "c:\someLocation\Report1.pdf"
    Kill "c:\someLocation\Report2.pdf"

End Sub

For the signature you could just append some html or try this:
http://www.codeforexcelandoutlook.com/blog/2008/08/add-your-signature-to-pre-formatted-emails/

hth
Chris
 

meccer

New member
Local time
Today, 18:37
Joined
Apr 13, 2011
Messages
4
Thank you Stopher, your code works perfect.

Just one enquiry is their a way that the email will open in Outlook before sending, just for if additional content wants to be added in the body and then the message will be sent when Send button is pressed.
 

stopher

AWF VIP
Local time
Today, 21:37
Joined
Feb 1, 2006
Messages
2,395
Thank you Stopher, your code works perfect.

Just one enquiry is their a way that the email will open in Outlook before sending, just for if additional content wants to be added in the body and then the message will be sent when Send button is pressed.
Just change the .Send line to .Display
 

rick roberts

Registered User.
Local time
Today, 21:37
Joined
Jan 22, 2003
Messages
160
can i butt in here stopher? ive tried your code changing it to rtf format but cant get it to work - when i click the appropriate button it either goes through the motions (i see the message box for a split second) then nothing, or it opens the vb screen but shows no error

Function SendEmail()

Dim appOutLook As Object
Dim MailOutLook As Object

'create the two reports temporarily
DoCmd.OutputTo acOutputReport, "rptLetter1", acFormatRTF, "d\data files\Report1.rtf", False


'assign our object references
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
'set the recipient list
.To = Email

'set the subject
.Subject = "My Reports"

'set the body text
.body = "Here are the reports in pdf format"

'add the reports we created
.attachments.Add "d\data files\Report1.rtf"

'send the email
.Send
End With

'tidy up..

'get rid of our object references
Set appOutLook = Nothing
Set MailOutLook = Nothing

'delete our temporary files
Kill "d\data files\Report1.rtf"

End Function

any ideas?
thanks in anticipation
 

rick roberts

Registered User.
Local time
Today, 21:37
Joined
Jan 22, 2003
Messages
160
oops
i did that but still doesnt send i put a stop on the last line and looked for the file - it does exist in the directory also i tried .Display instead of .Send and that works???
 

CBrighton

Surfing while working...
Local time
Today, 21:37
Joined
Nov 9, 2010
Messages
1,012
I use Access 2003 with 2 custom functions (1 in access, 1 in Outlook) to bypass security windows and send the email without any prompts to the user.

This function (which I had never seen before) on Access 2007 (which I rarely use) is unknown to me, so noticing the missing ':' is about the limit of my knowledge on this.

Sorry. ;)
 

rick roberts

Registered User.
Local time
Today, 21:37
Joined
Jan 22, 2003
Messages
160
sorry to be giving you false info -- ive just realised that im using the wrong record and sending the emails somewhere else lol but it still opens the vb screen if left in the background obviously not a problem when fully working -- but i stil lwonder why its doing that
 

CBrighton

Surfing while working...
Local time
Today, 21:37
Joined
Nov 9, 2010
Messages
1,012
Silly question, but I assume "To = Email" was edited to remove the email address for posting here and does have a valid email address in your code?
 

rick roberts

Registered User.
Local time
Today, 21:37
Joined
Jan 22, 2003
Messages
160
yes thats right - Email is the name of the textbox so that it sends to the saved email address for that person/record - ive just had to send an apology to the person concerned -- they will have a stack of test emails in their inbox - not a good day so far
thanks for your help
 

kgatesman

New member
Local time
Today, 13:37
Joined
Jun 7, 2012
Messages
6
I am trying this too, and tried to adapt this code to send a single report. I have this code set up to run when a job description form is Closed. It does nothing, doesn't trigger an error even.

I also have noted that in my External Data menus, Create Email is greyed out. I have tried various forms of this code too: Docmd.Sendobject acSendReport, "reportname", acFormatPDF and nothing happens. I am wondering if these issues are connected (Perhaps the IT Masters at work are not allowing me to do this)?

I know very little about what all this code means, so thanks for bearing with me.

My code looks like this:


Public Sub SendEmail()
Dim appOutLook As Object
Dim MailOutLook As Object


DoCmd.OutputTo acOutputReport, "Submitted Jobs", acFormatPDF, "C:\Users\Me\Documents\Submitted Jobs", False


'assign our object references
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
'set the recipient list
.To = "me(a)mycompany(dot)com"

'set the subject
.Subject = "New Job"

'set the body text
.body = "Evaluate the job"

'add the reports we created
.attachments.Add "C:\Users\Me\Documents\Submitted Jobs"


'send the email
.Send
End With

'tidy up..

'get rid of our object references
Set appOutLook = Nothing
Set MailOutLook = Nothing
'delete our temporary files
Kill "C:\Users\Me\Documents\Submitted Jobs"


End Sub
Private Sub Form_Close()
End Sub
 
Last edited:

jwpg2

New member
Local time
Today, 13:37
Joined
May 29, 2013
Messages
1
Using Access 2007, Microsoft Outlook 2007. Tweaked the code a bit - I'm getting an error message that says " Variable not defined - and OlMailItem in the Assign our object references section is highlighted. What should I do?

Private Sub Command53_Click()
' Public Sub SendEmail()

Dim appOutLook As Object
Dim MailOutLook As Object

'create the two reports temporarily
DoCmd.OutputTo acOutputTable, "Research - ETM Summary Table", _
acFormatXLS, "C:\OLD_D_DRIVE\PROJECTS\ETM_TEST\Research - ETM Summary Table.XLS", False
DoCmd.OutputTo acOutputQuery, "qry_Daily_Detail_Regions", _
acFormatXLS, "C:\OLD_D_DRIVE\PROJECTS\ETM_TEST\Research - ETM Detail Table.XLS", False

'assign our object references
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
'set the recipient list
.To = "test@test.com"

'set the subject
.Subject = "My Reports"

'set the body text
.body = "Here are the reports"

'add the reports we created
.attachments.Add "C:\OLD_D_DRIVE\PROJECTS\ETM_TEST\Research - ETM Summary Table.XLS"
.attachments.Add "C:\OLD_D_DRIVE\PROJECTS\ETM_TEST\Research - ETM Detail Table.XLS"

'send the email
'.Send
.Display

End With

'tidy up..

'get rid of our object references
Set appOutLook = Nothing
Set MailOutLook = Nothing

'delete our temporary files
'Kill "c:\someLocation\Report1.pdf"
'Kill "c:\someLocation\Report2.pdf"

End Sub
 

JohnHmmmm

New member
Local time
Today, 16:37
Joined
Mar 14, 2017
Messages
2
New newbie here, and I hope this is the best way to get an answer.
I am modifying a DB. It has an e-mail function that populates the subject line in the emaildatabase object macro function.
I want to populate the subject line with more of the fields of the current record, but I am running into the 255 character limit in the subject line box. Is my only option to go to a Visual Basic solution similar to what is shown in this thread that will not have any limits?
Here is what I have @ 255 characters: =[Forms]![Main]![NavigationSubform].[Form]![OpenedDate] & (" ") & [Forms]![Main]![NavigationSubform].[Form]![Delivery Number] & (" ") & [Forms]![Main]![NavigationSubform].[Form]![Category] & (" - Issue ") & [Forms]![Main]![NavigationSubform].[Form]![ID]


I need to add another field. Any suggestions? Thank you!
 

Users who are viewing this thread

Top Bottom