Solved

Error sending Outlook 2007 email from Access 2007 on XP

Posted on 2012-04-03
10
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

688 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