Hello Forum!
When I am running this code on a Windows XP platform whit Outlook2010 and Access2010 the code are working,
when I am running the same code on a Windows10 platform with Outlook2010 and Access2010 the code are NOT working, it stops at
.To = Me.Emailkontaktperson
and gives this message " Run-time error ' 2147417851 (80010105) Method'To' of object'_MailItem'failed "
Do Forum have any suggestion to what are causing this???
Private Sub Kommandoknap35_Click()
Dim DocName As String
Dim objOutlook As Object
Dim objOutLookMsg As Object
Dim strBody As String
Dim DocPath As String
Dim rst As DAO.Recordset
'Me.txtBillingEmail is a text field on the invoice form that has the billing email
'On Error GoTo Kommandoknap35_Click_Error
If Me.Emailkontaktperson = "No billing email on file." Then
'When a customer has no email the system inserts the text
'"No billing email on file."
MsgBox "No billing email on file.", vbInformation, "Can't Email"
Exit Sub
End If
'The DocName is the name of the invoice report
DocName = "RapTilbud"
'First, we open the report to the screen using the invoice #
DoCmd.OpenReport "RapTilbud", acViewPreview, , "[Ordrenr]=" & Me.Ordrenr
'DocPath stores the complete path of the PDF
'DocPath = CurrentProject.path & "\Fakturanr" & " " & Me.Ordrenr & " " & Me.Kundenavn & " .pdf"
DocPath = "C:\Users\Carsten\Desktop\Tilbud2doo" & "\Tilbud nr" & " " & Me.Ordrenr & " " & Me.Kundenavn & ".pdf"
'Delete pdf if it exists
If Dir(DocPath) <> "" Then
Kill DocPath
End If
'Second, we save the invoice to the directory where the program is launched from
'we use the invoice number in the name of the file
'DoCmd.OutputTo acOutputReport, DocName, acFormatPDF, CurrentProject.path & "\Fakturanr" & " " & Me.Ordrenr & " " & Me.Kundenavn & " .pdf", False
DoCmd.OutputTo acOutputReport, DocName, acFormatPDF, "C:\Users\Carsten\Desktop\Tilbud2doo" & "\Tilbud nr" & " " & Me.Ordrenr & " " & Me.Kundenavn & ".pdf", False
'Close the report since it's no longer needed
DoCmd.Close acReport, DocName
'rst is opened to the options table that holds the subject and body templates
Set rst = CurrentDb.OpenRecordset("Select * from Masterdata")
'objOutlook will be used to refence Outlook in the program
'I recommend Outlook is open while the code is executing
Set objOutlook = CreateObject("Outlook.Application")
'Create a new message:
Set objOutLookMsg = objOutlook.CreateItem(0)
With objOutLookMsg
'Use the email field on the invoice for the To field
.To = Me.Emailkontaktperson
'Optional: copy another email address that will receive a copy of the pdf
'.CC = "any@what_ever.com”"