Alpha Video Training
Results 1 to 5 of 5

Thread: Problem closing file after using REPORT.SAVEAS() in AfterUpdateRecord event

  1. #1
    Guest
    Real Name
    Tarek El Mohamad
    Join Date
    Nov 2005
    Posts
    34

    Default Problem closing file after using REPORT.SAVEAS() in AfterUpdateRecord event

    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

    Code:
    '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.)

  2. #2
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,682

    Default

    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.

    Quote Originally Posted by Tarek
    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

    Code:
    '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.)

  3. #3
    Guest
    Real Name
    Tarek El Mohamad
    Join Date
    Nov 2005
    Posts
    34

    Default

    Quote Originally Posted by Lenny Forziati
    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.

  4. #4
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,682

    Default

    The following code works for me. Change the report name and to address as appropriate for your case and give it a try

    Code:
    '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.)

  5. #5
    Guest
    Real Name
    Tarek El Mohamad
    Join Date
    Nov 2005
    Posts
    34

    Default

    Quote Originally Posted by Lenny Forziati
    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

Similar Threads

  1. Filter in report.saveas problem
    By Pat Bremkamp in forum Web Application Server v7
    Replies: 6
    Last Post: 11-14-2005, 11:53 AM
  2. Problem with filter in Report.saveas()
    By robert swanson in forum Web Application Server v6
    Replies: 10
    Last Post: 10-28-2005, 09:14 PM
  3. Report.Saveas Problem/Question
    By jwolfe11 in forum Alpha Five Version 5
    Replies: 1
    Last Post: 02-12-2004, 07:37 AM
  4. :report.saveas() problem
    By martinwcole in forum Alpha Five Version 5
    Replies: 2
    Last Post: 04-30-2003, 02:25 PM
  5. help with report.SaveAs
    By gkeramidas in forum Alpha Five Version 5
    Replies: 4
    Last Post: 02-15-2003, 07:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •