Minddumps
Registered User.
- Local time
- Today, 06:31
- Joined
- Jul 5, 2011
- Messages
- 73
SOLVED--SEE BELOW TRAFFIC
I was given the suggestion to save the report to desktop, then email that saved doc (pdf), then delete the saved doc.
My reports open up using the same query that my form was run on. I'm assuming I need to somehow combine the two codes that I have for save and then email but am stuck on how to email the saved doc, and also how to delete the file that was saved. Is anyone willing to advise?
This is the code I have so far:
I was given the suggestion to save the report to desktop, then email that saved doc (pdf), then delete the saved doc.
My reports open up using the same query that my form was run on. I'm assuming I need to somehow combine the two codes that I have for save and then email but am stuck on how to email the saved doc, and also how to delete the file that was saved. Is anyone willing to advise?
This is the code I have so far:
Code:
Private Sub EmailAll_Click()
On Error GoTo Err_Email_Click
Dim strReport As String
Dim stEmail As String
Dim stSubject As String
Dim MyFilename As String
Dim MyPath As String
Dim MyFilename As String
Dim ShowPdf As Boolean
strReport = "rpt-INSPECTION-WORKSHEETS"
Me.Refresh
'I place the file on the user's desktop
MyPath = "C:\Documents and Settings\" & Environ("USERNAME") & "\Desktop\"
'State the filename. Here I use YYYY-DD-MM-RecordID Group--Inspection Checklist.pdf
MyFilename = Format(Date, "yyyy") & _
"-" & Format(Date, "mm") & "-" & Format(Date, "dd") & _
"-" & [RecordID] & " Group--Inspection Checklist" & ".pdf"
'Open the report using the form's query and save.
If Me.Filter = "" Then
MsgBox "Apply a filter to the form first."
Else
DoCmd.OpenReport "rpt-INSPECTION-WORKSHEETS", acViewReport, , Me.Filter
Reports(strReport).Visible = False
End If
ShowPdf = False
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, MyPath & "\" & MyFilename, True
'Starting Email code
stSubject = "Inspection Sheet " & Me!RecordID & "group"
'Here is where I need the code to attach the previously created form on the desktop to an email
Exit_Email_Click:
Exit Sub
Err_Email_Click:
MsgBox Err.Description
Resume Exit_Email_Click
'Then here is where I need the code to delete that file on the desktop
'Finally, close our previewed report
DoCmd.Close acReport, strReport, acSaveYes
End Sub
Last edited: