mikenelena
Board Regular
- Joined
- Mar 5, 2018
- Messages
- 139
- Office Version
- 365
- Platform
- Windows
I have code that, among other things, is supposed to generate an Outlook e-mail from Access, and save that e-mail to a folder. The code works in a PC Windows 10 environment, but we are testing in Windows Server 2012 R2, and the code is throwing an error at the line in red below. We've tried simplifying the path to just save to the desktop, so I really don't think the path itself is the problem. Seems that HOMEPATH command may not be right for a server environment. If anyone can help me to fix this, I would be most grateful. Thanks in advance!
Code:
Private Sub cmdCAL_Click()
Dim strDocName As String
Dim strWhere As String
Dim objEmailItem As MailItem
Dim strSaveName As String
Dim StrName As String
Me.Refresh
If Len(Dir("S:" & "\Google Drive\" & [Forms]![Invoicing_Form]![Report Appraiser] & "\" & [Forms]![Invoicing_Form]![Invoice_Number], vbDirectory)) = 0 Then
MsgBox "This folder is not in Google Drive. It might have been deleted or moved to Archives."
Then
Exit Sub
Else
DoCmd.OpenReport "Acknowledgement Letter", acViewPreview, "", "[Invoice_Number]=Forms![Invoicing_Form]![Invoice_Number]", acNormal
DoCmd.OutputTo acOutputReport, "Acknowledgement Letter", "PDFFormat(*.pdf)", "S:" & "\Google Drive\" & [Forms]![Invoicing_Form]![Report Appraiser] & "\" & [Forms]![Invoicing_Form]![Invoice_Number] & "\Acknowledgement Letter " & [Forms]![Invoicing_Form]![Claim Number] & ".pdf", False, "", 0, acExportQualityPrint
Appraiser] & "\" & [Forms]![Invoicing_Form]![Invoice_Number] & "\Acknowledgement Letter " & [Forms]![Invoicing_Form]![Claim Number] & ".pdf", False, "", 0, acExportQualityPrint
StrName = "Acknowledgement Letter " & [Report_Acknowledgement Letter]![Claim Number]
Set objOutlook = GetObject(, "Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = New Outlook.Application
End If
Set objEmailItem = objOutlook.CreateItem(objlMailItem)
With objEmailItem
.Display
.To = [Report_Acknowledgement Letter]![E-mail3]
.CC = [Report_Acknowledgement Letter]![email3] 'Delete any existing reply recipients
If Me.[Client Name] = "Redacted Client Name" Then
.Subject = [Report_Acknowledgement Letter]![Claim Number] & " Acknowledgement Letter - " & [Report_Acknowledgement Letter]![Vehicle Owner]
Else
.Subject = "Acknowledgement Letter " & [Report_Acknowledgement Letter]![Claim Number] & " " & [Report_Acknowledgement Letter]![Vehicle Owner]
End If
.HTMLBody = "******>Dear " & [Report_Acknowledgement Letter]![First Name] & "," & "
" & "
" & "Our claim acknowledgement letter is attached. Please contact our appraiser directly if you have any questions." & vbNewLine & Signature
.Attachments.Add "S:" & "\Google Drive\" & [Forms]![Invoicing_Form]![Report Appraiser] & "\" & [Forms]![Invoicing_Form]![Invoice_Number] & "\Acknowledgement Letter " & [Forms]![Invoicing_Form]![Claim Number] & ".pdf"
[B][COLOR=#ff0000]objEmailItem.SaveAs Environ("HOMEPATH") & "\Google Drive\" & [Forms]![Invoicing_Form]![Report Appraiser] & "\" & [Forms]![Invoicing_Form]![Invoice_Number] & "\" & StrName & ".msg", olMSG[/COLOR][/B]
End With
Set objEmailItem = Nothing
Set objOutlook = Nothing
End If
End Sub
Last edited: