Solved

Error sending Outlook 2007 email from Access 2007 on XP

Posted on 2012-04-03
10
209 Views
Last Modified: 2012-04-12
My application can send Outlook 2007 email from Access 2007 on Vista or Windows 7 but when I try to run it on XP I get the "%1 is not a valid Win32 application" error. Any thoughts other than upgrading the XP machine?
0
Comment
Question by:jnero
  • 6
  • 4
10 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37801357
I run Access 2007 with email automation all the time with no issues...

Is this win xp machine fully updated...?
Did you develop the app in a 64 bit OS?

Can you post your code?

A general rule is to always develop in/for the lowest configuration.
For example if you develop an app in Access 2007, win 7 64 bit, who is to say that it will work in Win 3.0, Win 2000? Win Millienum,..et al?
If you even think that you might have to support a lower system, then develop for that system (if at all possible)
0
 

Author Comment

by:jnero
ID: 37801450
Thanks.  The problem may be that I developed it on the Windows 7 machine, which is definitely 32 Bit, I edited it further on the Vista machine, which I don't believe is 64 bit, but I can check that tonight.

The XP machine is running 5.1.2600 Service Pack 3- Build 2600

Here is the code:

Private Sub Sendemail_Click()

   Dim stDocName As String
   Dim stLinkCriteria As String
If Not IsNull(FaceID) Then
   stDocName = "frmFaces"
   stLinkCriteria = "FaceID=" & Forms![frmMaster2]![frmTransactionSubform].Form![With Whom]
   
   DoCmd.OpenForm stDocName, , , stLinkCriteria
 
End If
   
     DoCmd.OpenForm "frmFaces"
    Dim t As String
    t = Forms![frmFaces].EMAIL
    DoCmd.Close
    DoCmd.OpenForm "frmMaster2"
         
Dim MyOutlook As Outlook.Application
Dim MyEmail As Outlook.MailItem
 
Set MyOutlook = CreateObject("Outlook.application")
Set MyEmail = MyOutlook.CreateItem(olMailItem)

MyEmail.To = t
MyEmail.Subject = Forms![frmMaster2].Form![Headline]
MyEmail.body = Forms![frmMaster2]![frmTransactionSubform].Form![Notes] & vbCrLf & GetSignature("PR")
 
MyEmail.display

Dim Clip As String
Dim textonly As String

Clip = Forms![frmMaster2].Form![Headline] 'make the line shorter for coding purposes
textonly = InStr(Clip, "#")
Clip = Replace(Clip, "#", "") 'remove the #s
MyEmail.Subject = Mid(Clip, 1, textonly - 1)
   
End Sub

   Function GetSignature(strSignatureName As String) As String
    Const ForReading = 1
    Const TriStateTrue = -1
    Dim objFSO As Object, objFile As Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(Environ("USERPROFILE") & "\Application Data\Microsoft\Signatures\" & strSignatureName & ".txt", ForReading, False, TriStateTrue)
    GetSignature = objFile.ReadAll
    objFile.Close
    Set objFile = Nothing
    Set objFSO = Nothing
   

End Function
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37801855
what line are you getting the error on...?
0
 

Author Comment

by:jnero
ID: 37801872
Set MyOutlook = CreateObject("Outlook.application")
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37802260
Are you loading a reference to the Microsoft Outlook Object Library in your VBE?

In other words, if we remove all the extraneous stuff and jsut focus on the Email...
Then something like this should work fine:
Code modified from here:
http://support.microsoft.com/kb/161088

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    With objOutlookMsg
        ' Add the To recipient(s) to the message.
        Set objOutlookRecip = .Recipients.Add("SomeEmailAddress")
        objOutlookRecip.Type = olTo
       
        ' Set the Subject, Body, and Importance of the message.
        .Subject = "This is an Automation test with Microsoft Outlook"
        .Body = "This is the body of the message."
   
       
        ' Resolve each Recipient's name.
        For Each objOutlookRecip In .Recipients
            objOutlookRecip.Resolve
        Next
       
        .Display
    End With

Set objOutlook = Nothing
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:jnero
ID: 37802346
I have been loading the reference to the Microsoft Outlook Object Library.  

Tried the new code and still get the error here:
Set objOutlook = CreateObject("Outlook.Application")
0
 

Author Comment

by:jnero
ID: 37802361
If it makes a difference, I had the same script running fine when I was running Access 2003 on this XP machine.
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 37802433
Then something is seems awry with that XP machine...

Can you try this on another PC with Win XP?

Again I run Outlook automation via Acc 2007 and Win XP all the time, with no issues
0
 

Author Comment

by:jnero
ID: 37802869
Good idea -- I do have another XP machine. Will try that tonight. Thanks.
0
 

Author Comment

by:jnero
ID: 37815844
Unfortunately the other XP machine was running OLK 2003 and the problem is with 2007, so I have some reloading to do. Will update next week.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now