• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Email code only working on one comptuer

I thought this was solved, but turns out it is not. This below code is only working one computer. The debug highlights the         objEmailMessage.To = Forms!MainForm.txtEmail I also tried objEmailMessage.To = Forms!MainForm.[Email]

Both only work on one computer, not the other one. Any ideas?

Set objOutlook = CreateObject("Outlook.Application")
        Set objEmailMessage = objOutlook.CreateItem(olMailItem)
        objEmailMessage.To = Forms!MainForm.txtEmail
        objEmailMessage.Subject = sSubj
        objEmailMessage.htmlBody = sBody & vbCrLf & vbCrLf
        objEmailMessage.Display
        objEmailMessage.Attachments.Add "C:\Invoices\CustomerInvoices.pdf"

Open in new window

0
cansevin
Asked:
cansevin
  • 3
  • 3
  • 3
  • +2
1 Solution
 
arnoldCommented:
You are relying on outlook object meaning outlook must be installed and likely configured on the system.

Open outlook on the one where it does not work, are you getting promoted to create a new email account?
0
 
Rey Obrero (Capricorn1)Commented:
what is the error ?
0
 
Nick67Commented:
Look at my last suggestion on the previous question!
Throw a MsgBox in there.
What do you get back?

And this is not the whole code.
Post the entire sub.
I suspect you have On Error resume Next on the go because you haven't read
http://www.experts-exchange.com/articles/17466/Properly-open-Outlook-as-an-Application-object-in-VBA.html
and there is no end of grief that On Error Resume Next can cause!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
cansevinAuthor Commented:
The error just says to Debug... then it highlights that line of objEmailMessage.To = Forms!MainForm.txtEmail

Nick I'll look into your other post
0
 
Rey Obrero (Capricorn1)Commented:
in that error message box, there is an error number and description of error, at least try to read the message.
0
 
cansevinAuthor Commented:
Sorry... the error:

Method 'To' of object '_MailItem' failed
0
 
Nick67Commented:
I'll give you a 99/100 guess
Open Outlook on both machines.
Try to run your code.
Does it succeed or bomb on both
Or is one different than the other.
I suspect both bomb.

Now ensure that Outlook is closed on both machines.
Same experiment.
Same result?
I suspect both succeed

When you try this
Set objOutlook = CreateObject("Outlook.Application")
With Outlook open already, a 429 error will occur.
Sometimes, people throw in On Error Resume Next to deal with that.
But it's not dealt with!
It's ignored
So objOutlook is nothing.
so this line is going to fail, too
Set objEmailMessage = objOutlook.CreateItem(olMailItem)
And on error resume next makes the code ignore that too.
But then, finally, it gives up the ghost and stops.
0
 
cansevinAuthor Commented:
Any ideas on possible solutions?
0
 
Rey Obrero (Capricorn1)Commented:
in the computer that is failing, check the References and see if you have MISSING reference
uncheck and locate available reference

do a Debug > Compile and correct any errors raised
0
 
Nick67Commented:
Any ideas on possible solutions?
You haven't really given us anything to go on yet
In #40765893 I posted some troubleshooting steps to take to see if the problem is machine-specific or is in fact related to the open-status of Outlook
In #40765776 I asked you to flange in a MsgBox to see if a valid email is being sent to the line of the debug stop.
I have speculated that you have On Error Resume Next in your routine, and asked for you to post the entire subroutine so we can look at all the possibilities.
I've posted a link to an article about how you should open Outlook, and not the manner you are presently doing it

But this was your feedback
Any ideas on possible solutions?
You haven't confirmed or denied anything I've speculated about yet, so the ball is firmly still in your court.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Do you have the olMailItem constant declared somewhere in your code?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 3
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now