I am struggling with printing invoices with StarZens VPE classes and sending these as attachments to E-mails. The invoices are opened in a cszVpeReportView and from there a dbView is called within OnBeforeMail if the mails shall be sent with Chilkat. In this dbView, the user can make further changes in the E-mail and then either send it or cancel the operation. Now the previews are maintained after the mails are sent and have to be closed manually, but it would be much better if they were closed by the program when mails are sent successfully.

However, I haven’t found any hook in the calling cszVpeReportView that can be used for that. It seems as program execution never returns to that view. Normally I would have used OnVpeAfterMail, but that procedure is not executed when the VPE mail function isn’t used and that one only works on certain systems. If I put Send DoVpeCloseDoc in this view it works and (phDocument(Self)) has a value. But there is no good place to put that statement.

Therefore I tried to put it in the called view where the E-mail is sent. There, Send DoVpeCloseDoc gives an error “Invalid function call” and (phDocument(Self)) shows the same error in Watches.

Is there a solution to this problem? Can VPE documents only be closed in the view where they are opened?

Bengt