Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Corrupted attachment for outlook via Access 2

Status
Not open for further replies.

fldbryan

Programmer
Jan 22, 2004
46
US
I am having difficulty with this one module. It is supposed to attach a spreadsheet and then allow the user to finish filling out the Outlook form before sending it.

The problem seems to be that the attachment is arriving corrupted.

Does anyone have any answers?

Code:
Private Sub Form_Open(Cancel As Integer)
    Set MyOlApp = CreateObject("Outlook.Application")
End Sub

Sub AddAttachment(TMail)
    Dim myItem As Object 'Outlook.MailItem
    
    Set myItem = MyOlApp.CreateItem(olMailItem)
    myItem.To = TMail
    myItem.Subject = "Weekly Open Requisition Report"
    myItem.Attachments.Add "C:\OpenRequisitions.XLS", olByValue, 1, "OpenRequisitions"
    myItem.Body = "Attached is your open requisition report. Please note this includes all lines of business. If you have any questions, contact the assigned recruiter." & vbCrLf & "Thank You"
    myItem.Display
End Sub

Private Sub Form_Close()
    MyOlApp.Quit
End Sub
 
The problem seems to be that the attachment is arriving corrupted.

What exactly do you mean by that, be more specific!

What error msg you get?

What makes you think it might be corruption

I don't see how attachment gets corrupted.....

?!?
 
When the email arrives the attachment cannot be opened. It says the file format is wrong for this (Excel) application.
 
I think you should take a look at TomCologne link, that is most likely it... it probably sends it has ritch text format
 
My biggest problem is that I need a message and the attachment to go out. Is there a solution for that? Do you think doing body ahead of attachment would work? is there a way to force text mode when generating the email.
 

Nope!
I've tried all kinds of code, then half VBA -to create body or attachment- half manual method -open the message & add either one manually but everything changed the format to !@#$%^*.rtf!

I hope you can proof me wrong.

And you just got to love MS's statement:
"Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article."


TomCologne
 
fldbryan

I was using OL2000, doing that for 2 attachments in a loop of ~350 steps and didn't experience that. But I was using in a bit different way
Code:
With myItem
   .To = TMail
   .Subject = "Weekly Open Requisition Report"
   .Attachments.Add "C:\OpenRequisitions.XLS", olByValue, 1, "OpenRequisitions"
   .Body = "Attached is your open requisition report. Please note this includes all lines of business. If you have any questions, contact the assigned recruiter." & vbCrLf & "Thank You"
   .Display
End With
I hope you can fool the machine and get over with that.

And a suggestion.
Code:
Private Sub Form_Close()
If Not MyOlApp Is Nothing Then
  MyOlApp.Quit
  Set MyOlApp = Nothing
End If
End Sub
 
"Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article."

Yeah that makes me feel better......

Now how about a fix MS?

 
Now how about a fix MS?
Upgrade to the XP or 2003 version.
 
I am running Outlook 2003. :p

That being said I did find a solution

Code:
    Set myItem = MyOlApp.CreateItem(olMailItem)
    myItem.To = TMail
    myItem.Subject = "Weekly Open Requisition Report"
    myItem.Body = "Attached is your open requisition report. Please note this includes all lines of business. If you have any questions, contact the assigned recruiter." & vbCrLf & "Thank You" & vbCrLf & "Jennifer Richard" & Chr$(0)
    myItem.Attachments.Add "C:\OR_" & GUserID & ".XLS", olByValue, 1, "OpenRequisitions"
    myItem.Display

I did body first and ended with Chr$(0). Then I followed it up with the attachment and it worked. It was just a guess from my old C days of ending strings with a null.

I hope this helps others
 
Since the XP version:
myItem.BodyFormat = olFormatPlain

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Every piece helps. The null character will probably work with Outlook 2000, but I can't test it.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top