UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V  1 2 >  (Go to first unread post)
   Reply to this topicStart new topic
> Method 'to; Of Object '_mailtem' Failed, Access 2013    
 
   
Thor
post Jan 12 2018, 01:25 PM
Post#1



Posts: 487
Joined: 15-November 10



Hi all, long time no 'see'! notworthy.gif

Since i last visited this paradise we transitioned to Windows 10 and Office 2013 on a 64bit system. The issue is that some users are experiencing the Method 'To; of object '_Mailtem' failed error whilst others are not, despite the fact we are all on the same 'systems' as mentioned above. Below code is used and is referenced in the debug window for the error...what is going on? Has anyone experienced the same thing? What should i be looking for?

With objEmail
.TO = Me!SalesRep
.CC = Me!CCFIELD
.Subject = Me!SUBJECTLINE
.HTMLBody = strBody
.Attachments.Add (txtAttachment)

Thanks!

Go to the top of the page
 
cheekybuddha
post Jan 13 2018, 06:32 AM
Post#2


UtterAccess VIP
Posts: 10,647
Joined: 6-December 03
From: Telegraph Hill


Please post the whole code including the declarations
Go to the top of the page
 
Thor
post Jan 13 2018, 11:59 AM
Post#3



Posts: 487
Joined: 15-November 10



Sure cheekybuddha, as previously mentioned some user are experiencing the error and cannot execute..for others it works just fine...i did not include the 'text' after strEmail = txtEmail for the sake of privacy...Thanks!

If IsNull(Me.txtAttachment) Then
CancelEvent = True
MsgBox "You need to select an attachment!"

Else


Dim strEmail, strBody As String
Dim objOutlook As Object
Dim objEmail As Object
Dim strAttachmentPath As String
Dim Signature As String

Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(0)

Signature = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(Signature, vbDirectory) <> vbNullString Then
Signature = Signature & Dir$(Signature & "*.htm")
Else:
Signature = ""
End If
Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll

strEmail = txtEmail

With objEmail
.TO = Me!SalesRep
.CC = Me!CCFIELD
.BCC = "fraudbase@monster.com"
.Subject = Me!SUBJECTLINE
.HTMLBody = strBody & "<br />" & "<IMG src=""C:\FraudBaseGlobal\image001.png"">" & Signature
Set objOutlookAttach = .Attachments.Add("C:\FraudBaseGlobal\EN - Sharing Proactive Outreach FAQs.doc")
Set objOutlookAttach = .Attachments.Add("C:\FraudBaseGlobal\EN - Resume license sharing outreach program.pptx")
Set objOutlookAttach = .Attachments.Add("C:\FraudBaseGlobal\Understanding the impacts - account and CV license sharing GBR.pdf")
.Attachments.Add (txtAttachment)





.Send

End With
Forms![CasesSingleView].[EMAILED] = "Yes"
DoCmd.OpenForm "LSEEMAILOthercfm"
CurrentDb.Execute "INSERT INTO dbo_EMAILLOG ([CASE_ID]) VALUES (" & CaseID & " );"
End If
End Sub
Go to the top of the page
 
cheekybuddha
post Jan 13 2018, 01:32 PM
Post#4


UtterAccess VIP
Posts: 10,647
Joined: 6-December 03
From: Telegraph Hill


Nothing obvious jumps out at me.

Is Me!SalesRep ever Null? If so, it would probably cause an error.

Otherwise, perhaps the eyes of others will spot what I haven't.

hth,

d
Go to the top of the page
 
cheekybuddha
post Jan 13 2018, 01:41 PM
Post#5


UtterAccess VIP
Posts: 10,647
Joined: 6-December 03
From: Telegraph Hill


Actually, perhaps you copied code from a duff source!

Look here
>> This property [TO] contains the display names only <<

Try adjusting your code:
CODE
' ...
  With objEmail
    .Recipients.Add Me!SalesRep
    With .Recipients.Add Me!CCFIELD
      .Type = 2    ' olCC
    End With
    With .Recipients.Add "fraudbase@monster.com"
      .Type = 3    ' olBCC
    End With
    .Subject = Me!SUBJECTLINE
    .HTMLBody = strBody & "<br />" & "<IMG src=""C:\FraudBaseGlobal\image001.png"">" & Signature
' ...


hth,

d
Go to the top of the page
 
Thor
post Jan 13 2018, 02:21 PM
Post#6



Posts: 487
Joined: 15-November 10



Thanks cheekybuddha, i will try this out and let you know outcome, much appreciated! notworthy.gif
Go to the top of the page
 
Thor
post Jan 15 2018, 02:29 PM
Post#7



Posts: 487
Joined: 15-November 10



Could the patches related to the 'Meltdown' and 'Spectra' issue affect Access VBA? How can i find out?

Just a thought out of the blue.....

Go to the top of the page
 
cheekybuddha
post Jan 16 2018, 06:09 AM
Post#8


UtterAccess VIP
Posts: 10,647
Joined: 6-December 03
From: Telegraph Hill


Interesting thought, but I doubt it.

More likely an Office update may be responsible if it worked before, but doesn't now.

Did the code changes help?

d
Go to the top of the page
 
Thor
post Jan 16 2018, 09:37 AM
Post#9



Posts: 487
Joined: 15-November 10



Hi cheekybuddha,

Unfortunately not, I receive syntax error related to the two below lines

.Recipients.Add fraudbase@monster.com
.Subject = Me!SUBJECTLINE

Thanks!
Go to the top of the page
 
cheekybuddha
post Jan 16 2018, 09:40 AM
Post#10


UtterAccess VIP
Posts: 10,647
Joined: 6-December 03
From: Telegraph Hill


Did you copy and paste this from your actual code?

.Recipients.Add fraudbase@monster.com

You need quote marks around the email address:
CODE
.Recipients.Add "fraudbase@monster.com"


hth,

d
Go to the top of the page
 
Thor
post Jan 16 2018, 09:49 AM
Post#11



Posts: 487
Joined: 15-November 10



I did paste from the actual code including the quotas cheekybuddha
Go to the top of the page
 
cheekybuddha
post Jan 16 2018, 10:11 AM
Post#12


UtterAccess VIP
Posts: 10,647
Joined: 6-December 03
From: Telegraph Hill


There were no quotes in what you posted.

Please copy and paste your whole code here
Go to the top of the page
 
Thor
post Jan 16 2018, 10:17 AM
Post#13



Posts: 487
Joined: 15-November 10



This is the code:

With objEmail
.Recipients.Add Me!SalesRep
With .Recipients.Add Me!CCFIELD
.Type = 2 ' olCC
End With
With .Recipients.Add "fraudbase@monster.com"
.Type = 3 ' olBCC
End With
.Subject = Me!SUBJECTLINE
.HTMLBody = strBody & "<br />" & "<IMG src=""C:\FraudBaseGlobal\image001.png"">" & Signature

Thanks for your patiance!
Go to the top of the page
 
cheekybuddha
post Jan 16 2018, 10:20 AM
Post#14


UtterAccess VIP
Posts: 10,647
Joined: 6-December 03
From: Telegraph Hill


You are missing an End With at the end.

Try:
CODE
With objEmail
  .Recipients.Add Me!SalesRep
  With .Recipients.Add Me!CCFIELD
    .Type = 2 ' olCC
  End With
  With .Recipients.Add "fraudbase@monster.com"
    .Type = 3 ' olBCC
  End With
  .Subject = Me!SUBJECTLINE
  .HTMLBody = strBody & "<br />" & "<IMG src=""C:\FraudBaseGlobal\image001.png"">" & Signature
End With


hth,

d
Go to the top of the page
 
Thor
post Jan 16 2018, 10:29 AM
Post#15



Posts: 487
Joined: 15-November 10



I use your code and receive syntax error on the following lines:


With objEmail
.Recipients.Add Me!SalesRep
With .Recipients.Add Me!CCFIELD
.Type = 2 ' olCC
End With
With .Recipients.Add "fraudbase@monster.com"
.Type = 3 ' olBCC
End With
.Subject = Me!SUBJECTLINE
.HTMLBody = strBody & "<br />" & "<IMG src=""C:\FraudBaseGlobal\image001.png"">" & Signature
End With
Go to the top of the page
 
cheekybuddha
post Jan 16 2018, 10:43 AM
Post#16


UtterAccess VIP
Posts: 10,647
Joined: 6-December 03
From: Telegraph Hill


Apologies, since in those 2 lines you are using the .Add() method as a function which returns a Recipient object, its argument must be enclosed in parentheses.

Try instead:
CODE
With objEmail
  .Recipients.Add Me!SalesRep
  With .Recipients.Add(Me!CCFIELD)
    .Type = 2 ' olCC
  End With
  With .Recipients.Add("fraudbase@monster.com")
    .Type = 3 ' olBCC
  End With
  .Subject = Me!SUBJECTLINE
  .HTMLBody = strBody & "<br />" & "<IMG src=""C:\FraudBaseGlobal\image001.png"">" & Signature
End With


hth,

d
Go to the top of the page
 
Thor
post Jan 16 2018, 10:54 AM
Post#17



Posts: 487
Joined: 15-November 10



Now i get a runtime error 'Method 'Subject of object'_Mailtem' failed and checking into the debugger it is related to below line

.Subject = Me!SUBJECTLINE

Thanks!
Go to the top of the page
 
cheekybuddha
post Jan 16 2018, 11:03 AM
Post#18


UtterAccess VIP
Posts: 10,647
Joined: 6-December 03
From: Telegraph Hill


Please post the whole code of your procedure, from Private Sub to End Sub
Go to the top of the page
 
Thor
post Jan 16 2018, 11:26 AM
Post#19



Posts: 487
Joined: 15-November 10



Hi Martin, this is the enire code, however, i have omitted some text parts due to 'privacy'...
Private Sub LSEMAILERBUTTONUSA1_Click()

If IsNull(Me.txtAttachment) Then
CancelEvent = True
MsgBox "You need to select an attachment or to populate the field Assigned/Username. Thanks!"

Else


Dim strEmail, strBody As String
Dim objOutlook As Object
Dim objEmail As Object
Dim strAttachmentPath As String

Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(0)

strEmail = txtEmail

strBody = strBody & "<font style=""font-family:Calibri, Verdana, Geneva, sans-serif;font-size:11pt;"">Hi " & SRFIRSTNAME & ", <br />" & Chr(13) & Chr(13)
strBody = strBody & "<br />" & Chr(13) & Chr(13)

strBody = strBody & "<hr style=""height:2pt; color:#673694;""<br />"
strBody = strBody & "<font style=""font-family:Verdana, Geneva, sans-serif; font-size:9pt; color:#4c4c4c;"" ><strong>" & FULL_NAME & "</strong> | " & USER_LOCATION & " <br /><br />"
strBody = strBody & USER_EMAIL & " | T: " & USER_TELEPHONE & "<br /><br />"
strBody = strBody & USER_ADDRESS & "" & USER_POSTCODE & " </font><br />"



With objEmail
.Recipients.Add Me!SalesRep
With .Recipients.Add(Me!CCFIELD)
.Type = 2 ' olCC
End With
With .Recipients.Add("fraudbase@monster.com")
.Type = 3 ' olBCC
End With
.Subject = Me!SUBJECTLINE
.HTMLBody = strBody & "<br />" & "<IMG src=""C:\FraudBaseGlobal\image001.png"">" & Signature
End With




Forms![CasesSingleView].[EMAILED] = "Yes"
DoCmd.OpenForm "LSEEMAILUSAcfm"
CurrentDb.Execute "INSERT INTO dbo_EMAILLOG ([CASE_ID]) VALUES (" & CaseID & " );"
End If
End Sub

Go to the top of the page
 
cheekybuddha
post Jan 16 2018, 11:50 AM
Post#20


UtterAccess VIP
Posts: 10,647
Joined: 6-December 03
From: Telegraph Hill


OK,

Do you have Option Explicit declared at the top of every module, above/below Option Compare Database ?

If not, then add it to the top of all your modules.

Then, Debug->Compile

I'm wondering whether there are other code errors somewhere causing your code to fail.

Also, please check whether you have a reference set for Outlook (in VBA Editor, Tools->References) - you shouldn't need one, since your code appears to be late-bound, but it would be good to know anyway.

What version of Outlook do you have installed?
Go to the top of the page
 
2 Pages V  1 2 >


Custom Search


RSSSearch   Top   Lo-Fi    17th December 2018 - 02:45 PM