Modules & VBA :: How To Send A Report Via Outlook 2010
Oct 30, 2014
I have a VBA module in my Access 2010 database that will send a report as a PDF via email to a predetermined email address. the only problem using the docmd.sendobject method is i keep getting a pop up that says "A program is trying to send an e-mail on your behalf. If this is unexpected, click Deny and verify your antivirus software is up-to-date."
I have a windows task set up at the same time each day to open this database which runs an autoexec that creates this report and using my VBA module sends the email. i want it to just send the email without any imput from me. I want automation.
Here is my code that i am using to create and send the email
"Private Sub Report_Activate()
filename = "Name of file" & Format(Me.Date_time_returned "MMDDYY") & ".pdf"
DoCmd.SetWarnings False
DoCmd.SendObject acSendReport, "Name of file", acFormatPDF, "the destination email address goes here",,, "Request completed and sent " & Format(Me.Date_time_returned, "MMDDYY"), "Subject of email goes here", False
DoCmd.SetWarnings True
End Sub"
A client wants to e-mail newsletters using a non-default Outlook account. The code below does everything the client needs except setting the SendUsingAccount. In debug I can see that the correct account is assigned, yet all of my testing results in e-mails where the From line is the default account. The test setup uses my own isolated SMTP server, so when I look at the e-mails sent the sender is the default account. The default account's Sent folder shows the sent mail, which is not what we want.
Code: Sub prepEmail() Dim frm As Form, startDate As Date, endDate As Date Dim rs As DAO.Recordset, strSQL As String, intNewsLetter As Integer Dim rsEmail As DAO.Recordset, rsNewsletters As DAO.Recordset Dim OlApp As Object, ol As Object Dim olMail As Object, olAcct, olAcctTemp
I'd like a command button to open Outlook and create a new email message with the To and Subject fields already populated with what I want, is there anyway to do this?
With this construction I don't have enough control over the mail, and worse, I get an Outlook message when the mail is sending which I have to answer.
2. option
Code: Dim oMail As MailItem Dim oAtt As Attachment
Set oApp = CreateObject("Outlook.application") Set oMail = oApp.CreateItem(olMailItem) DoCmd.OpenReport ReportName:=sReport, View:=acViewPreview, WindowMode:=acHidden Set rpt = Reports(sReport)
[code]...
with this construction I have to enter an existing report.pdf on my filesystem (bold line), but I want to pass the rpt object straight to the mail as an attachment.
Is there a way of doing the above? I have several distribution lists (some >100 recipients) defined in Outlook, and would like to use the Docmd. Send Object command to send messages to one or several of them. I cannot find a way of defining a distribution list as any of the To, Cc or Bcc parameters.
I have the code below which takes information from a form on access and sends it over to the correct place on an excel spreadsheet template. This works fine but I then need it to save and send on outlook.
The issue I am having is that the saved document is not attaching to the e-mail. The subject etc all work fine but the excel spreadsheet just doesn't attach. When I go into the folder I have specified for the document to be saved in it isn't there either. :0(
The code for the e-mail "callmail" function works perfectly for word documents but I don't know if it is different for an excel file.
Code:
Private Sub Command154_Click() On Error Resume Next Dim appExcel As Excel.Application Dim wbook As Excel.Workbook Dim wsheet As Excel.Worksheet Set appExcel = New Excel.Application
I'm trying to have a command button send info on the form straight to Outlook as a meeting. So far, the code below works apart from the address bit. I need the code to automatically add the same 2 email addresses as recepients everytime.
Error message highlights the red line below with the following message:
Runtime error '438' Object doesn't support this property or method
I'm new to VBA, so don't understand what is wrong here. The reference is set, I've tried different permutations of the "To:" & "Recipients.Add" for the email address with no joy.
Code: Private Sub cmdSend_Click() Dim outApp As Object Set outApp = CreateObject("Outlook.application") Set outmail = outApp.CreateItem(olappointmentitem)
My company recently upgraded our MS Office from 2007 to 2010 (except for Access).
Previously, when I had Access 2007 and Outlook 2007, I had a process that generated 50+ dynamic emails from an Outlook template file (.oft).
The code would loop through a listbox and replace the template's default text to a string of text specific to the selection in the listbox by utilizing the Replace() function on the MailItem .HTMLBody.
Since the upgrade to Outlook 2010, the code is able to run, however, the Replace() function is no longer working; Instead, each email that is generated maintains the template's default text.
The only thing that is not working is the Replace() function, all other aspects of the code work fine.
I've provided a simplified version of the code below:
Dim myOlApp As Outlook.Application Dim objMailMessage As MailItem Dim stBody As String Set myOlApp = Outlook.Application Set objMailMessage = myOlApp.CreateItemFromTemplate("C:UsersDesktop emplate.oft")
[Code] .....
I've recreated the template file in Outlook 2010, thinking that the template created with Outlook 2007 would be the culprit, but to no avail.
What could have changed from Outlook 2007 to Outlook 2010 that would render my previously valid code ineffective?
Are there certain references I need to enable in both Access and Outlook to allow VBA in Access modify the content in an Outlook email?
I wish to work in Access 2010 with a subset of my Outlook 2010 contacts (all desktop- no network barriers), so I am exploring the Desktop Contacts DB found in Microsoft's templates. It passes contact data back and forth using the standard macros, but I wish to add more fields from Outlook. It seems I need to find the code associated with the macro. I believe I can solve the problem using a Linked table, but am wondering if there is another solution?
Calendar synchronization is another issue. Linking gets me to the Archive Calendars, but not the Current one in Outlook which is what I want.
I use this to send email msgs through gmail, found it on the net somewhere, adapted a bit and it works.
Code: Private Function fSendGmail() As Boolean 'Returns True if No Errors are Generated On Error GoTo Err_ErrorHandler fSendGmail = True Const conStrPrefix As String = "http://schemas.microsoft.com/cdo/configuration/" Const conCdoSendUsingPort As Integer = 2
[Code] ....
Err_ErrorHandler: If Err.Number <> 0 Then fSendGmail = False etc, etc End Function 'fSendGmail
I'd like to send report attached to this as pdf or rtf. How should I go about it. I know how to create pdf and save it.(DoCmd.OutputTo acOutputReport, "My Report", acFormatPDF, strPath, True) But where do I attach that here? Is it necessary to save the file first?
I use a macro that attaches a document automatically to an e-mail address ready to send this report is governed by a query of which the criteria is " loss order number " this is in a pdf format of which I need if possible
The problem I have is the same pdf file keeps attaching itself to the e-mail no matter which loss order number I select. The reason I think is because the report is called NCR so it is not changing from the previous one. What I think can solve it but not sure and don't know how to do is get the " loss order number " within the report name.
If I just send the report to a file direct it does work as I am prompted for a file name
Can the loss order number get into the file name within a macro/vba
Can you send a report directly to the printer? We have Clients with multiple Contact Notes, by multiple Clinicians, each of these are separate tables. Every month we print two reports for each client that had at least one contact in that date-range. Usually 200 clients, takes a lot of time. My approach so far is a query within a make-table query to get a list of unique client ID's that had one contact in the date-range. Then I use that table in code to create a recordset, use a Do Loop within that where I print the two reports for the 1st client, move to next record and loop. Now that I've got it working I'm not sure how to print all the reports My 1st question, can you send a report directly to the printer from code? The printer is a networked Konica Minolta Biz-hub so I think it can handle that many jobs being queued that fast.
I have copied a VBA from the net and it is working fine and producing my report on outlook body text but one problem me facing is that it is pasting only first page if the second page is there it is not coming in outlook text body this what i want rest every thing is correct the code is:
Private Sub Command88_Click() Const ForReading = 1, ForWriting = 2, ForAppending = 3 Dim fs, f Dim RTFBody, strTo Dim MyApp As New Outlook.Application Dim MyItem As Outlook.MailItem
Am working in MS Access 2013 and I have a form with a button, I need the button to doattach automatically the pdf-report to the email template(i don't want to attach the pdf to a new email)
Right now the command open the E-mail template and create the pdf-report in the desktop
Code: Private Sub Command18_Click()
Dim oApp As Outlook.Application Dim oMsg As Outlook.MailItem Dim oAttachment As Outlook.attachment Set oApp = New Outlook.Application
I am using the following code (Sendobject) to create a PDF of a report and send it via email to a customer's email address.
Private Sub EmailWorkOrderQuote_Click() On Error GoTo Err_EmailWorkOrderQuote_Click Dim stDocName As String Dim mFilename As String Dim mEmailAddress As String
[Code] ....
It works fine except that the I want to to able to utilize the ability to send the email with either both the CC and BCC or either or neither as well.
I have a table called "My Company Information" that contains the email addresses for the CC and BCC. If I have values in these fields, everything works great! If I have no values in either of these fields, I get "Invalid use of Null"....
I want to be able to use either both CC and BCC, either CC or BCC, or neither used and it still work.
Hoping someone can help - need to know if there is a way to use a Outlook message other than the blank one that is used with the send object macro.
Maybe a normal message with a signature, template or something - when the macro is run, no formatting is included with the e-mail message, and the body of the message is limited to 255 charaacters.
Would like to use a customized message, and I need the send object macro to place the object in that message format.
If anyone can help, I would greatly appreciate it...thanks.
I am trying to modify the following code to send an automated e-mail using Microsoft Outlook instead of Lotus Notes. We recently switched e-mail clients and now the older code does not work. I have tried to comment in all areas to indicate where the new Outlook code has been inserted.
Private Sub SendEmail(ByVal Subject As String, ByVal Body As String) 'The bulk of this code for Lotus Notes comes from this website: Dim copy(100) As Variant Dim strSQL As String Dim rsTemp As Recordset Dim Maildb As Object 'The mail database Dim UserName As String 'The current users notes name
I have a contact form on our website which sends an email to the business dev team saying that the user has requested to be sent product sheets. The email contains the users name, email, phone number, and a few other fields. Is there a way I can send the details of these emails to my access database automatically?
I'm trying to use Access to send an automatic email reply upon receiving a request from a customer/employee, telling them that their request has been received and this is the tracking number and the due date of service completion. How can I do that? And I want it using Outlook because all the contacts are saved in Outlook and all emails sent and received through Outlook. And the version is Access 2010.
I have been trying to import Outlook (2010) floders into Access 2010. So far, I have only been able to import 1 folder at a time. I have also tried linking the access database to Outlook, not much luck there.What I was wanted to do was import the pst / ost file into access and then work from there.is there a way to import the Inbox and all sub-folders at one time.
We are currently using Access 2007 and I've got a database that sends emails out to multiple users depending on the data that was entered. We are about to upgrade to Access 2010 and I am testing it now. I was originally getting runtime error '287' when I was adding addresses to a Recipient object. I got past that by adding the addresses in a string and concatenating. Now I'm getting the error with .Send.
I created a Tracking System and would like to send an automatic reminder to the person the ticket has been assigned to, using the due date and the text message in the field "reminder message". Once the message send, I want the database to recognize and not send it again. I want the database to send a new message if the due date has changed.
I know how to create new table in Access by linking to Outlook contacts. The problem is, the default NOTES field in the Outlook contact does not show up in the linked Access table. Every Outlook Contact field shows up with the exception of that one field.