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.Attachments.Add "C:\Invoices\CustomerInvoices.pdf"

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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?
Rey Obrero (Capricorn1)Commented:
what is the error ?
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
and there is no end of grief that On Error Resume Next can cause!
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
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.
cansevinAuthor Commented:
Sorry... the error:

Method 'To' of object '_MailItem' failed
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.
cansevinAuthor Commented:
Any ideas on possible solutions?
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Do you have the olMailItem constant declared somewhere in your code?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.