Marcin
Rzadkowalski
Kierownik produkcji,
All Sealing
Solutions
Temat: Wysylanie raportu mailem jako PDF
Witam wszystkich,Mam prosbe o pomoc przy napisaniu kodu.
Chcialbym wyslac raport w formacie PDF z tym ze raport ma byc pogrupowany i zapisany do PDF w osobnych plikach.
Pewnie nie jasno to opisalem ale jesli znalazl by sie ktos chetny to postaram sie to uscislic.
W chwili obecnej mam kod ktory generuje mi PDF ale tylko jeden i nie potrafie sobie poradzic w utwozeniem petli.
Sub cmdReportPDF_Click()
Dim i As Integer
Dim objol As Object
Dim objmail As Object
Dim objFolder As Object
Dim fso As Object
Dim fsFolder As Object
Dim fsFile As Object
Dim FileName As String
Dim FilePatch As String
Dim oOutlook As Outlook.Application
Dim strItem As String
'---------------------------------------------------------------------------------------//
'// Create various needed objects. I happen to use late-binding. //
Set fso = CreateObject("Scripting.FileSystemObject")
ObjstartFolder = "C:\Temp\Access"
Set fsFolder = fso.GetFolder(ObjstartFolder)
'// Create .PDF files//
DoCmd.OpenReport "Cert_Archer", acViewPreview
strItem = [Reports]![Cert_Archer]![Trinf1]
FileName = strItem + ".pdf"
FilePatch = "C:\Temp\Access\"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, FilePatch + FileName, False
DoCmd.Close acReport, "Cert_Archer"
'//Create Email with attachment//
Set objol = CreateObject("Outlook.Application")
Set objmail = objol.CreateItem(0) '(olMailItem)
If oOutlook Is Nothing Then
Set oOutlook = New Outlook.Application
End If
With objmail
.To = "Me@Wherever.com"
.Subject = ""
.Body = "Here's a test"
.NoAging = True
'// Using the file system object, return/add all the PDF files in the picked //
'// folder. //
For Each fsFile In fsFolder.Files
If fsFile.Name Like "*.pdf" Then
.Attachments.Add "C:\Temp\Access" & "\" & fsFile.Name
End If
Next
.Display
End With
errhndl:
Set objFolder = Nothing
Set fso = Nothing
Set fsFolder = Nothing
Set objol = Nothing
Set objmail = Nothing
End Sub
Pozdrawiam Marcin