If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
email as a pdf
I am using Access 2003
I have a form th choose the report and the email recipient and then click the email to send. I need the report to be sent in pdf format. I tried the below code but got error - variable not defined. Whats wrong with this?? Private Sub cmdEmail_Click() On Error GoTo Err_cmdEmail_Click Dim strDocName As String Dim strEmail As String Dim strMailSubject As String Dim strMsg As String strDocName = Me.lstRpt strEmail = Me.txtSelected & vbNullString strMailSubject = Me.txtMailSubject & vbNullString strMsg = Me.txtMsg & vbNullString & vbCrLf & vbCrLf DoCmd.SendObject objecttype:=acSendReport, _ ObjectName:=strDocName, outputformat:=acFormatPDF, _ To:=strEmail, Subject:=strMailSubject, MessageText:=strMsg Exit_cmdEmail_Click: Exit Sub Err_cmdEmail_Click: MsgBox Err.Description Resume Exit_cmdEmail_Click I am getting error - variable not defined. What am I doing wrong? -- deb |
#2
|
|||
|
|||
email as a pdf
You do should a debug-compile, as then ms-access will higlight any code
that has a probem (this is far easiwer then trying to read all your code). Anyway, the problem is ms-access 2003 does not have PDF ability built in. so, your code as posted will only work for access 2007. the soluoer for using version previous to access 2007 is to install a pdf system on your compurter. There is a free pdf system for ms-access that can be had he http://www.lebans.com/reporttopdf.htm Using the above means your have to create the pdf output document FIRST and THEN launch outlook, and THEN attach the pdf You can NOT use sendobject to do this (except for access 2007). So, you code will look like Public Sub MySendObject(strSubject As String, _ strMsgText As String, _ strEmailTo As String, _ strDocName As String) send to user via email Dim ol As Object Late binding 10/03/2001 - Ak Dim ns As Object Late bind Dim newmessage As Object Late bind Dim mymessage As String Set ol = GetObject(, "Outlook.Application") Set ns = ol.GetNamespace("MAPI") ns.Logon Set newmessage = ol.CreateItem(0) 0 = olMainItem With newmessage .Recipients.Add strEmailTo .Subject = strSubject .Body = strMsgText If strDocName "" Then .Attachments.Add (strDocName) End If .Display .Send End With End Sub You could take the above code, and expand it with stephans pdf creater. You get: Public Sub EmailReport(strReportName As String, _ strSubject As String, _ strMsgText As String, _ strDocName As String, _ strEmailTo As String) sends the active report out.... send to user via email Dim MyReport As Report Dim ol As Object Late binding 10/03/2001 - Ak Dim ns As Object Late bind Dim newmessage As Object Late bind Dim mymessage As String 'DoCmd.OutputTo acReport, strReportName, acFormatRTF, strDocName, False Call ConvertReportToPDF(strReportName, , strDocName, False, False) DoCmd.Close acReport, strReportName On Error GoTo CreateOutLookApp Set ol = GetObject(, "Outlook.Application") On Error Resume Next Set ns = ol.GetNamespace("MAPI") ns.Logon Set newmessage = ol.CreateItem(0) 0 = olMainItem With newmessage .Recipients.Add strEmailTo .Subject = strSubject .Body = strMsgText .Attachments.Add (strDocName) .Display .Send End With Exit Sub CreateOutLookApp: Set ol = CreateObject("Outlook.application") Resume Next End Sub -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada |
Thread Tools | |
Display Modes | |
|
|