Reference problem? emailing with outlook

Zaeed

Registered Annoyance
Local time
Today, 23:35
Joined
Dec 12, 2007
Messages
383
Hey, i have some code that launches outlook. It used to work, however it now gives me an error along the lines of..

Run-time error '-2147417848 (80010108)'
Automation error
The object invoked has disconnected from its clients.

here is my code
Code:
Option Compare Database
Option Explicit


Public Function Distribute(newEmail As Boolean, list As String, rejected As Boolean)

' Determine who gets mailed
'''' What level of notification
'''' What departments
' Extract emails
' Send emails


Dim strline, strHTML

 Dim OL As Outlook.Application
  Dim MyItem As Outlook.MailItem

  Set OL = New Outlook.Application
  Set MyItem = Outlook.Application.CreateItem(OL)
  If Not rejected Then
    If newEmail = True Then
      DoCmd.OutputTo acOutputReport, "report1", acFormatHTML, "C:\myreport.html" '' seeking approval
    Else
      DoCmd.OutputTo acOutputReport, "report2", acFormatHTML, "C:\myreport.html" '' approved
    End If
  Else
    DoCmd.OutputTo acOutputReport, "report3", acFormatHTML, "C:\myreport.html"  '' rejected
  End If
  
  Open "C:\myreport.html" For Input As 1
  Do While Not EOF(1)
    Input #1, strline
    strHTML = strHTML & strline
  Loop
  Close 1
  ' If OL2002 set the BodyFormat
  If Left(OL.Version, 2) = "10" Then
    MyItem.BodyFormat = olFormatHTML
  End If
  MyItem.HTMLBody = strHTML
  MyItem.To = list
  MyItem.Subject = "Change Management Submission"
  MyItem.Display

End Function
I found a reference from another site to requirement of Reference for Microsoft Office 12.0 Object Library.

In my reference list, I only have Office 11.0 Object Library.

Can someone help me?
 
Your problem is merily that you used to have Outlook referanced within your access application and now it is uninstalled .
Now questions that might help you solve your problem :
1 - have you upgraded your office installation ? if so have you upgraded / removed previous outlook installation ?
2 - have you downloaded any office service packs lately ?
3 - have you installed Microsoft ActiveSync product ?

* the answer to all of the above would just be reinstalling your microsoft office

4 - if none of the above occured , does your referances page have a broken referance ?

* remove all broken referances and try again , else reinstall microsoft office

5 - does it have multiple occurances of Microsoft Office 11.0 Object Library ?

* if so add all to your referances

Hope that helps
 
nah it just stopped working... on more than one computer.. the computer it originated on had office 2003 uninstalled, 07 installed, then uninstalled and 2003 put back on...
if that could have caused something to go wrong how could i fix it?
 
this could be the case , you used a referance to an object of office 2007 in office 2003 then removed it .. hmm .. can i suggest that you just let all that go and use :
SendObject function ? it will shorten the above entire script into a line or 2 , use ms help for proper syntax or check out this thread i engaged in erlier
http://www.access-programmers.co.uk/forums/showthread.php?t=157939
 
I might give that a go..

However I think i've narrowed the problem to this bit of code

Code:
  If Not rejected Then
    If newEmail = True Then
      DoCmd.OutputTo acOutputReport, "report1", acFormatHTML, "C:\myreport.html" '' seeking approval
    Else
      DoCmd.OutputTo acOutputReport, "report2", acFormatHTML, "C:\myreport.html" '' approved
    End If
  Else
    DoCmd.OutputTo acOutputReport, "report3", acFormatHTML, "C:\myreport.html"  '' rejected
  End If

I know it would be nicer as a switch statement but nevermind that.
I did a step through of the code and found that the code hangs on the docmd.outputto line, which makes me think thats whats causing the disconnect error..

The basic idea of the code is that it transforms a report to a .html file and then uses that as the body of the email..

Is there something wrong with the code? Or is there another way of doing what i want?
 
Save yourself some hassle with references and change this code:
Code:
 Dim OL As Outlook.Application
  Dim MyItem As Outlook.MailItem

  Set OL = New Outlook.Application
  Set MyItem = Outlook.Application.CreateItem(OL)

to this:
Code:
 Dim OL As Object
  Dim MyItem As Object

  Set OL = CreateObject("Outlook.Application")
  Set MyItem = OL.CreateItem("MailItem")
 
That gives me a different error Bob.

RunTime 424
Object Required

on the ' Set OL = CreateObject("Outlook.Application")' line
 
not really no.. I still think the issue is with the docmd.outputTo is there another way to do this? since i want to have a Report be the body of the email
 
@Nightmayor

using this line
Code:
  DoCmd.SendObject acSendReport, "report2", acFormatHTML, list, , , "subject here", "message body here"

i get an error
Runtime 2293
"my project name here" can't send this e-mail message
 
DoCmd.SendObject acSendReport, "report2", acFormatHTML, "client mail here!", , , "subject here", "message body here"
 
DoCmd.SendObject acSendReport, "report2", acFormatHTML, "client mail here!", , , "subject here", "message body here"


yeah, the above line is what i had, still didnt work...

I've made progress though guys.

I've found that the issue im having is not with the code, but rather the task of launching Outlook when it isn't running.. If I have Outlook going the code works a treat.

So, how do I fix this? I assume its some sort of security feature?
 
zaeed !?
you substitute the between quotation section in the above code with real values ?
hello ?
 
zaeed !?
you substitute the between quotation section in the above code with real values ?
hello ?


hmm? I used your code with real values yes...

I build a list of emails in the form of --> "name@domain.com"; "name2@domain.com" <--

That is called list
That's what i had in the reference above , when testing i was just using "fred", but it works out the same.


I've reverted back to the OL = CreateObject("Outlook.Application") method sorry Nightmayor. The SendObject was working just the same..

I found the same issue with the SendObject as I have with the CreateObject, and that is that when Outlook is not running, the code won't work.. Outlook must be running before running the code..

How do I fix this? I believe it to be some sort of security function, but i cant find anything to help...
 
Can I confirm that you do have 'Microsoft Outlook 11.0 Object library' added to your references list, as well as Office?
 
Yes... as well as office and access and a bunch of others..

Is it possible to have a corrupt reference?



So far I have found the that the issue is that Outlook refuses to be opened by Access.
If I use the OL = createobject("outlook.application") method then I get an automation error.
If I use the DoCmd.SendObject method, with the edit option to True then it gives an error saying the email can't be sent..
If I set edit to False then the email gets put the Outbox ready to be sent when Outlook is next launched, but this method gives the wait 5 second warning. Plus I want my users to be able to edit the email message before it is sent.
 
Last edited:
Ok, I fear I may have fixed it by uninstalling Avast anti virus...

Could that have been the cause? and if so, how would i combat it?
 
emails should be posted in same string..
use
"name@domain.com;name2@domain.com" instead of multiple strings seperated by ; like you did
 
also do note that sending mails throughout objects might be categorized as "worm" like activity and is halted by some antiviruses , yet an antivirus should pop up a confirmation dialogue or a warning at least. you can check and see if avast warnings are disabled.
still i would recommend the sendobject, you should give it better chance.
 

Users who are viewing this thread

Back
Top Bottom