I created a form that allows users to report bugs and request new feature. The form works fine, writing the data to a table and saving a report to the users document folder. It also sends me an email to me. That works, too, except it doesn't attach the report. I've attached the code. Can someone tell me where I'm making a mistake? (The irony of my bug report having a bug does not escape me!)
Thanks for any help you can give me.
Private Sub SendThis_Click()
Dim strSQL As String
strSQL = "INSERT INTO tbl_BugFeature(SubBy,BugDate,BugDesc,ReqDesc) VALUES(" & "'" & Combo18 & "'," & "'" & Text13 & "'," & "'" & Text4 & "'," & "'" & Text6 & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
On Error GoTo mcr_bugs_Err
Dim KillFile As String
KillFile = "BugFeature.pdf"
' 'Check that file exists
If Len(Dir(KillFile)) > 0 Then
' MsgBox "file exists"
' 'First remove readonly attribute, if set
SetAttr KillFile, vbNormal
' 'Then delete the file
Kill KillFile
End If
BugMax = DMax("[BugID]", "tbl_BugFeature", "[SubBy] = Combo18")
DoCmd.OpenReport "rpt_Bug", acViewPreview, , "BugID = " & BugMax
DoCmd.OutputTo acOutputReport, "rpt_Bug", "PDFFormat(*.pdf)", "BugFeature.pdf", False, "", , acExportQualityPrint
DoCmd.Close acReport, "rpt_Bug", acSaveYes
Dim olApp As Object
Dim objMail As Object
Dim strAttach1 As String
strAttach1 = "rpt_Bug.pdf"
On Error Resume Next 'Keep going if there is an error
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance
End If
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = "jackie.egan@evsck12.com"
.Subject = "Bug Report - Feature Request"
.HTMLBody = "<htmltags></htmltags>"
.Attachments.Add strAttach1
.Send
DoCmd.Close acForm, "frm_Bug"
DoCmd.OpenForm "frm_Main"
MsgBox "Your report has been emailed and a copy has been saved to your documents folder.", vbOKOnly, ""
mcr_bugs_Exit:
Exit Sub
mcr_bugs_Err:
MsgBox "There was a problem sending this report.", vbOKOnly, ""
DoCmd.Close acForm, "frm_Bug"
DoCmd.OpenForm "frm_Main"
End With
End Sub