Avatar billede jensen363 Forsker
30. september 2009 - 12:42 Der er 27 kommentarer og
1 løsning

Fejl ved Set objPost = objOl.CreateItem(olMailItem)

Nedenstående har fungeret de seneste 2 år unden problemer, men virker ikke mere af een eller anden årsag ...

Den virker i XP - Office 2003, men ikke Vista Office 2007

Nogen som kender en workaround ???

Public Function SendMail()
Dim objOl As New Outlook.Application
Dim objPost As MailItem
Dim vedhæftet As Attachments
   
Dim MyDB As Database
Dim MyRS As Recordset
 
Dim TOAddress As String
Dim CCAddress As String
Dim Message1 As String
Dim Message2 As String
       
    Set objPost = objOl.CreateItem(olMailItem)
   
    Set vedhæftet = objPost.Attachments
    vedhæftet.Add "\\Cphfil-01\Fil.xls"
       
    Set MyDB = CurrentDb
        Set MyRS = MyDB.OpenRecordset("tblMailingList")
    MyRS.MoveFirst

    TOAddress = MyRS![To]
    CCAddress = MyRS![cc]
   
    Message1 = " A "   
    Message2 = " B "

    With objPost
        .Subject = Message1
        .To = TOAddress
        .cc = CCAddress
        .Body = Message2
       
        '.Send
        .Display
       
    End With
 
  objOl.Quit
 
    Set objPost = Nothing
    Set vedhæftet = Nothing
   
Exit Function

errhandler:
   
    MsgBox "ERROR: " & Err.Number & " - " & Err.Description

End Function
Avatar billede terry Ekspert
30. september 2009 - 12:55 #1
you need a reference to Outlook (tools References)
Avatar billede terry Ekspert
30. september 2009 - 12:55 #2
.
Avatar billede jensen363 Forsker
30. september 2009 - 13:18 #3
I already have Microsoft Outlook 11.0 Object library active. This has been active all the time
Avatar billede terry Ekspert
30. september 2009 - 13:50 #4
If you compile the code do you get an error?
You may also need a reference to ADO whcih isnt defaulted in 2007
Avatar billede terry Ekspert
30. september 2009 - 13:57 #5
Dim objOl As Outlook.Application

Dim objPOst As MailItem


Set objOl = CreateObject("Outlook.Application")
Set objPost = objOl.CreateItem(olMailItem)
Avatar billede jensen363 Forsker
30. september 2009 - 16:46 #6
Hi Terry

Nothing of the suggested has an effect :-(
Avatar billede terry Ekspert
30. september 2009 - 17:23 #7
any chance of seeing the dB or part of?
Avatar billede jensen363 Forsker
01. oktober 2009 - 09:26 #8
Hi again

I don't think you will have any use of seeing the DB ( major application ) ....

The setup with the modules has been running for the past 2 years without any problems ... but our IT-department has done som modifications on the server ( citrix )

I haven't had any response as to what modifocations were made, the only hint I could find on WWW was regarding Vista and Office 2007 ... actually I'm quite sure that the modifications made has nothing to do with Vista or Office 2007, but probably a servicepack update ...

But I haven't got anything to work with :-(
Avatar billede terry Ekspert
01. oktober 2009 - 09:50 #9
I have code to send mails via Outlook running on Vista/Office 2007 with no problems.

Have you compiled the code without an errors?

What error do you get on the line?

Set objPost = objOl.CreateItem(olMailItem)
Avatar billede jensen363 Forsker
01. oktober 2009 - 10:02 #10
I get this message :

  Run-time error '2079129597 (8413003)'
  The operation failed.
Avatar billede jensen363 Forsker
01. oktober 2009 - 10:07 #11
I've found this :

http://www.pcreview.co.uk/forums/thread-3437477.php

Even though this is php code it looks loke the same problem
Avatar billede terry Ekspert
01. oktober 2009 - 11:21 #12
I've looked at that link and it could very well be the same problem.

You could start by changing your code so that you use OBJECT variables instead of Outlook. This has the advantage that it uses the newest version without having to change the reference.
But ther must obviously be a version installed.


As Object

and dont forget to remove the reference.
Avatar billede jensen363 Forsker
01. oktober 2009 - 15:19 #13
Hi terry

Any chance as to how my module should look like if I want to implement the "Late Binding" solution

I simply can't figure out where to place my original code to make it work :-(
Avatar billede terry Ekspert
01. oktober 2009 - 15:25 #14
I'll see if I can get something working here and get back ASAP
Avatar billede jensen363 Forsker
01. oktober 2009 - 15:30 #15
No stress :-)
Avatar billede terry Ekspert
01. oktober 2009 - 18:58 #16
Public Function SendMail()
Dim objOl As Object
Dim objPost As Object
Dim vedhæftet As Object
   
Dim MyDB As Database
Dim MyRS As Recordset
 
Dim TOAddress As String
Dim CCAddress As String
Dim Message1 As String
Dim Message2 As String


    Set objOl = CreateObject("Outlook.Application")
    Set objPost = objOl.CreateItem(olMailItem)
   
    Set vedhæftet = objPost.Attachments
    vedhæftet.Add "\\Cphfil-01\Fil.xls"
       
    Set MyDB = CurrentDb
        Set MyRS = MyDB.OpenRecordset("tblMailingList")
    MyRS.MoveFirst

    TOAddress = MyRS![To]
    CCAddress = MyRS![cc]
   
    Message1 = " A "
    Message2 = " B "

    With objPost
        .Subject = Message1
        .To = TOAddress
        .CC = CCAddress
        .Body = Message2
       
        '.Send
        .Display
       
    End With
 
  objOl.Quit
 
    Set objPost = Nothing
    Set vedhæftet = Nothing
   
Exit Function

errhandler:
   
    MsgBox "ERROR: " & Err.Number & " - " & Err.Description

End Function
Avatar billede terry Ekspert
01. oktober 2009 - 19:01 #17
The only difference is that the Outlook objects are declared as just OBJECT which I suggested tor. d. 01. oktober 2009 kl. 11:21:24


and a

Set objOl = CreateObject("Outlook.Application")

Then remove the reference in Tools references.
Avatar billede jensen363 Forsker
02. oktober 2009 - 08:30 #18
Hi Terry

I just wish it was that simple ( I've already tried that )

I still get the same error ....

In the meantime I have had some response from our IT-department telling me, that they have changed the Application Data file location on the application server .....

So this would be the next place to look .... however ff this is where the "dog is buried" it seems strange that all ohter OLE integration is stille running ( import/export data to excel )
Avatar billede terry Ekspert
02. oktober 2009 - 08:51 #19
"Application Data file location"
Not sure why that would give the error you get.

The error and information from the link you gave indicate that your not finding any version of Outlook.
Avatar billede jensen363 Forsker
02. oktober 2009 - 09:12 #20
:-(

I'm stuck ...

I simply can't se where the problem lies ...

I'll let you know if/when I solve the problem
Avatar billede jensen363 Forsker
02. oktober 2009 - 15:01 #21
Hi Terry

Had to re-invent DoDmd.SendObject to make it work again :-(
Avatar billede terry Ekspert
02. oktober 2009 - 16:21 #22
Thats a drastic step to take
Avatar billede jensen363 Forsker
02. oktober 2009 - 16:27 #23
I totally agree - but workable ...

Have a nice weekend, ant thanks for your effort
Avatar billede terry Ekspert
02. oktober 2009 - 17:58 #24
same to you.
Avatar billede jensen363 Forsker
27. oktober 2009 - 09:48 #25
Hi Terry

You'll get the points for your effort :-)
Avatar billede terry Ekspert
27. oktober 2009 - 10:01 #26
thanks
Avatar billede jensen363 Forsker
27. oktober 2009 - 10:11 #27
Our IT-department had to re-configure the fileserver and without knowing the exact problem, the problem has wanished ...
Avatar billede terry Ekspert
27. oktober 2009 - 11:54 #28
so one can assume that the first time it wasnt done correctly :o)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester