Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Saturday, August 23, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Add report as attachemnt from code
John Bennett
Posts: 34
 
Add report as attachemnt from codeYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Apr 08 10:11 AM
SLX v6.2.4

I am trying to write code that will take a Crystal report.... open the report, save it and then add as an attachment. I have seen previous posts but have not really understood the code that was posted so I sort of looked at them and pieced together the code below. It appears to do the above but when I send it to the recipient and they try to open the attachment it gives them an Outlook error stating "The system cannot find the file specified". I can not figure out why its doing this. I guess its not really "attaching" the file but still trying to look in the path on the users machine and obviously it not there.

The code I am using is below...I know its not the prettiest but its working (except for the part of attaching the file)

Set objNet = CreateObject("WScript.NetWork")

Application.GlobalInfo.Add "ReportID", txtcustomerOrderID.Text ' set a global for the report to use
rptPath = "C:\Documents and Settings\" & objNet.UserName & "\Local Settings\Temp\p6uj9a0015RK.pdf"
' i basically know the path ahead of time except for the users name so i set the path
Set filesys = CreateObject("Scripting.FileSystemObject")
If (filesys.FileExists(rptPath)) Then
filesys.DeleteFile(rptPath)
End If

Application.BasicFunctions.DoInvoke "CrystalReportPreview", "Unit:Customer Order WFreight"

at this point the user would save the report using all of the defaults that it walks you thru in the Crystal viewer
then the code continues...

If (filesys.FileExists(rptPath)) Then
Set oOApp = CreateObject("Outlook.Application")
Set oOMail = oOApp.CreateItem(olMailItem)
oOMail.Save
With oOMail
.To = ""
.Subject = "blah blah blah"
.Body = "blah blah blah blah"
.Attachments.Add rptpath, olByValue, 1
.Display
End With
End If

It opens Outlook..... the user selects the recipient to send to .....but when I have tested it they are not able to open..

If any body has any suggections or could send me a code example of when they did this and it worked would be great.

thanks

John

[Reply][Quote]
Jeremy Brayton
Posts: 491
Top 10 forum poster: 491 posts
 
Re: Add report as attachemnt from codeYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Apr 08 10:32 AM
.Attachments.Add(fileName) is all I use and my attachments show up fine. I'm not quite sure that your olByValue, 1 additions do much differently but that could have something to do with it.

Is it possible that the report is really a .rpt just saved with a .pdf extension? Can you open the attachment on your machine and adobe will display it fine? Have they upgraded reader? Crystal likely writes to a specific PDF version format and they may need a minimum version. You usually get a "this is in a newer format but we're showing it anyway" message but they could be on Acrobat 2 thinking it should just open.
[Reply][Quote]
John Bennett
Posts: 34
 
Re: Add report as attachemnt from codeYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Apr 08 10:42 AM
I thought it might have something to do with olByValue but using the parameter of 1 means to add it as a separate attachment.

i can open it on my machine if i send it to myself but that is probably because it CAN find the path...I have Adobe v7.0 Reader and so did the person I sent it to...
[Reply][Quote]
Jeremy Brayton
Posts: 491
Top 10 forum poster: 491 posts
 
Re: Add report as attachemnt from codeYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Apr 08 11:47 AM
When I need to add attachments, however many, I just make multiple calls to Attachments.Add with only the file parameter. It adds them into the little attachment pane at the bottom of the message.

If you're opening the file from your sent items, it's supposed to be grabbing it from the temporary internet files location in IE. The only time it should ever open the original location is if you attach a shortcut instead of the file itself. I don't think olByValue does that so you're almost guaranteed to be opening the file as the recipient should. If it's opening in Adobe, not Crystal, then it's creating the PDF correctly.

Have you tried getting the recipient to drag it to their desktop and open it there? If the IE cache gets full you can sometimes get weird issues like this, but I usually associate it with being able to download only a couple of images from a website, not adobe documents going limp. Does the recipient get an error message or is it just a "cannot open file" generic one?
[Reply][Quote]
John Bennett
Posts: 34
 
Re: Add report as attachemnt from codeYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Apr 08 1:21 PM
Jeremy

When you say file parameter do you mean just file name, i.e. "xyz.pdf" or do you give it the path name?

When the report opens, it opens to the regular Crystal report..the user would then click on the "Export Report" icon, chooses .pdf format and saves to disk file in the Temp folder with the internal SLX name, i.e. p6UJ9A......it saves the report. The user then closes the report and then my code kicks in and opens up Outlook with the subject, body , and attachemnt in the email. they pick the person they are sending to and off it goes. When you open the email up and clikc on the attachemnt that is when they get the error message ..... the error message has the title "Microsoft Office Outlook" and reads "The system cannot find the specified file"...

Thanks

John
[Reply][Quote]
John Bennett
Posts: 34
 
Re: Add report as attachemnt from codeYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Apr 08 3:52 PM
just thought of something....in my code above ...by declaring the variable rptPath as the path ...is the code attaching the text of the path or is it attaching the file?

any thoughts? can i declare the rptPath any different?
[Reply][Quote]
Mark Richardson
Posts: 25
 
Re: Add report as attachemnt from codeYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Apr 08 2:43 AM
Hi John,

Simply change the line:

.Attachments.Add rptpath, olByValue, 1

to:

.Attachments.Add rptpath

ie - OMIT the olByValue,1

This is a format for the attachment and basically, when declared as you have, tells outlook to attach a 'link' to the attachment, NOT the attachment itself

Mark
[Reply][Quote]
John Bennett
Posts: 34
 
Re: Add report as attachemnt from codeYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Apr 08 8:46 AM
Mark

that did the trick....works as it should now!!!

Thanks for the tip.

John
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 8/23/2025 10:29:03 AM