PDA

View Full Version : Problem closing file after using REPORT.SAVEAS() in AfterUpdateRecord event


ABC123

Tarek
11-30-2005, 05:23 PM
I'm trying to run an AfterUpdateRecord event from a grid component to save a report as an HTML file and then send it off in an e-mail. Unfortunately, I appear to be having a problem, as after the file is written, it doesn't appear that Alpha 5 ever closes the file and releases its lock on it. If I close Alpha 5, I can open the file, view it, etc. However, under normal (running) conditions, running the event again will not allow the file to get overwritten, nor does the email_send() command ever run due to this issue.

The message I get from the web server is:
500 Internal Server Error
Script Error
Error:File 'c:\test.htm' is in use. Cannot overwrite.

I've tried variations of the code to create the file prior to running report.saveas(), and then close it afterwards, but have not been successful.

Any suggestions on the code below would be greatly appreciated.

Thanks,
Tarek



'Save Report to File
name = "notif"
format = "HTML"
filter = ""
order = ""
filename = "c:\test.htm"
report.saveas(name,format,filter,order,filename,.F.)

'E-Mails Report as Attachment
addr = "hello@hotmail.com"
subject = "subject_line"
body = "msg body"
email_send(addr,subject,body,filename,"","",.T.,"HTML","","Default",.F.,.T.)

Lenny Forziati
11-30-2005, 05:38 PM
You should look at using report.send(). It will simplify your code as well as eliminate any timing issues potentially caused by trying to send the email before the file is finished generating.


I'm trying to run an AfterUpdateRecord event from a grid component to save a report as an HTML file and then send it off in an e-mail. Unfortunately, I appear to be having a problem, as after the file is written, it doesn't appear that Alpha 5 ever closes the file and releases its lock on it. If I close Alpha 5, I can open the file, view it, etc. However, under normal (running) conditions, running the event again will not allow the file to get overwritten, nor does the email_send() command ever run due to this issue.

The message I get from the web server is:
500 Internal Server Error
Script Error
Error:File 'c:\test.htm' is in use. Cannot overwrite.

I've tried variations of the code to create the file prior to running report.saveas(), and then close it afterwards, but have not been successful.

Any suggestions on the code below would be greatly appreciated.

Thanks,
Tarek



'Save Report to File
name = "notif"
format = "HTML"
filter = ""
order = ""
filename = "c:\test.htm"
report.saveas(name,format,filter,order,filename,.F.)

'E-Mails Report as Attachment
addr = "hello@hotmail.com"
subject = "subject_line"
body = "msg body"
email_send(addr,subject,body,filename,"","",.T.,"HTML","","Default",.F.,.T.)

Tarek
12-01-2005, 09:06 AM
You should look at using report.send(). It will simplify your code as well as eliminate any timing issues potentially caused by trying to send the email before the file is finished generating.

Lenny, thanks for the suggestion. I did have a look at that, but the help file indicated that using the report.send() method required a user to press a Send key to complete the transmission, so it seemed to me that report.saveas() and email.send() would be simpler and more WAS-friendly, as I'd like the event to run with minimal user interaction. Attempting to use just report.send(name,format,filter,order,"default",addr,subject, body) got me the following, instead:

500 Internal Server Error
Script Error
Error:Script:generic_layout_save_as line:294
Result stack underflow

In any case, the problem I seem to be having does not appear to be related to the the report file generating and the e-mail attempting to send it prior to completion. If I trigger the event and generate the file, even if I were to attempt to access the file hours later, the file would still be "in use", and thus not allow me to view, overwrite, delete or manually access it in any way. I did try commenting out the email_send() to test this and wound up with the same results using just the report.saveas() method.

Lenny Forziati
12-01-2005, 06:38 PM
The following code works for me. Change the report name and to address as appropriate for your case and give it a try



'Save Report to File
name = "customer list@c:\program files\a5v7\samples\alphasports\customer.dbf"
format = "HTML"
filter = ""
order = ""
filename = "c:\test.htm"
report.saveas(name,format,filter,order,filename,.F.)

'E-Mails Report as Attachment
addr = "user@domain.com"
subject = "subject_line"
body = "msg body"
email_send(addr,subject,body,filename,"","",.T.,"HTML","","Default",.F.,.T.)

Tarek
12-02-2005, 08:33 PM
The following code works for me. Change the report name and to address as appropriate for your case and give it a try


I tried the code you posted and received the same results, unfortunately. For the heck of it, I decided to try to change the format from HTML to PDF. At that point, it immediately started working without a hitch.

I have no idea why I experienced the problem with closing the file as HTML, but PDF format will certainly do it for me for now.

Thanks for your help, Lenny!

Regards,
Tarek