views:

29

answers:

0

This VB6 code worked fine in Windows XP with Outlook 2003.

Function SendMail(EM_TO, Em_CC, EM_BCC, EM_Subject, EM_Body, _
        EM_Attachment As String, Display As Boolean)
    Dim objOA As Outlook.Application
    Dim objMI As Outlook.MailItem
    Dim obgAtt As Outlook.Attachments
    Set objOA = New Outlook.Application
    Set objMI = objOA.CreateItem(olMailItem)
    If EM_TO <> vbNullString Then objMI.To = EM_TO
    If Em_CC <> vbNullString Then objMI.CC = Em_CC
    If EM_BCC <> vbNullString Then objMI.BCC = EM_BCC
    If EM_Subject <> vbNullString Then objMI.Subject = EM_Subject
    If EM_Body <> vbNullString Then objMI.Body = EM_Body
    If EM_Attachment <> vbNullString Then 
        objMI.Attachments.Add EM_Attachment, 1, , EM_Attachment
    End If

    If Display Then
        objMI.Display
    Else
        objMI.Send
    End If
    Set objOA = Nothing
    Set objMI = Nothing
End Function

I'm still using Outlook 2003, but the operating system is Windows 7 x64.

There are two problems:

  1. If Outlook is already open, it raises an error on Set objOA = New Outlook.Application. I tried using GetObject but it didn't seem to find the running instance.
  2. If Outlook is closed to start, it raises an error -1940651759 on objMI.Attachments.Add ("Unable to perform the operation. The information store could not be opened.")
  3. If I comment out the attachment line, it raises an error on the objMI.Display line (-1767636719 "The information store could not be opened.")

I'm guessing this is security-related. Perhaps it's due to the ost or pst file being in a more protected environment. Has anyone had to deal with this? Is there a different way that might work in Windows 7?

EDIT:

I discovered something else interesting. If I actually change Outlook to run as an administrator, or to tell it to run in Windows XP compatibility mode, then I get the same "The information store could not be opened" error when I start Outlook manually. It's interesting because the VB6 application (and development environment) are both running as administrator. I think it's related.