Hello everyone,
I have a monthly report I export as a PDF and email it to some ppl. It is a huge report and I am trying to export the report in a Ledger paper size, but I can't get this done. I would like your help on this,if possible.
This is the VBA code I have so far
I have a monthly report I export as a PDF and email it to some ppl. It is a huge report and I am trying to export the report in a Ledger paper size, but I can't get this done. I would like your help on this,if possible.
This is the VBA code I have so far
Code:
Public Function EmailLastMonthScrapReport()
On Local Error GoTo Some_Err
Dim MyDB As Database
Dim MyRS As Recordset
Dim MyRpt As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String
Dim RecordID As String
Dim lstRptName As String
Dim strDir As String
Dim strFile As String
Dim AttachmentPath As String
Dim blSkip As Boolean
Dim strAddress As String
Dim MyPosn As Integer
Dim strLen As Integer
Dim MultiEmailFlag As Boolean
' Create the Outlook session to allow creating the emails
Set objOutlook = CreateObject("Outlook.Application")
'Open Report to allow it to be filtered
DoCmd.OpenReport "rptNewScrapDetReport", acViewPreview
Reports("rptNewScrapDetReport").Printer.PaperSize = acPRPSLedger
' Set directories and file names for file archiving and storage
' Directory to place the PDF files that are to be printed
strDir = "Y:\Scrap Analysis\zz Auto Reports Monthly\"
' Name of file to create
strFile = Format(Date - 28, "YYYY") & " " & Format(Date - 28, "mmmm") & ".pdf"
AttachmentPath = strDir & strFile
' CREATE PDF REPORT HERE
Dim blRet As Boolean
blRet = ConvertReportToPDF("rptNewScrapDetReport", vbNullString, _
strDir & strFile, False, True, 150, "", "", 0, 0, 0)
'Close Report to allow it to be filtered
'End With
DoCmd.Close acReport, "rptNewScrapDetReport"
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipients to the e-mail message.
Set objOutlookRecip = .Recipients.Add("xxx@xxx.com")
objOutlookRecip.Type = olTo
Set objOutlookRecip = .Recipients.Add("xxx@xxx.com")
' Set the Subject, the Body, and the Importance of the e-mail message.
.Importance = olImportanceHigh 'High importance
.Subject = "Scrap Report for " & Format(Date - 28, "mmmm") & " " & Format(Date - 28, "YYYY")
' .Body = "Attached is..."
' .Body = .Body & " ..."
' .Body = .Body & Chr(13)
' .Body = .Body & Chr(13)
'Add the attachment to the e-mail message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
' If we have a valid email address for that supplier, then send message, otherwise,
' add in info for me to know we're missing something.
If (IsNull(objOutlookRecip)) Then
MsgBox ("No valid email address")
Else
.Send
End If
End With
' All done. Clean up
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Some_Err:
'MousePointer = 0
' MsgBox "Error (" & CStr(Err.Number) & ") " & Err.Description, _
' vbExclamation, "Error!"
Err_EmailLastMonthScrapReport:
' MsgBox Err.Description
' Resume EmailScorecards_Click
End Function