OnUnload agent does not run

Dear all,I need to run this agent on OnUnload event of a form

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Set doc = session.DocumentContext

Set db = session.CurrentDatabase	

Set view = db.GetView("BP_Import_vw")

dd=doc.IF_Hdn_LogUser(0)	

Set vc = view.GetAllEntriesByKey(dd)

vc.RemoveAll(True)	

End Sub

so i called the agent on a button as this

@Command([ToolsRunMacro]; “(Remove BusinessPF_Agt)”)

and call that buttons click event on OnUnload event as

form=document.forms[0];

if (confirm(“Do you want to close?”))

		{

form.Close_Agt.click();

}

this works fine when i call this on a another button(close button)

can anyone please tell me why this doesn’t run on OnUnload event

thanks in advance

shana

Subject: OnUnload agent does not run

Without further testing I would assume, that OnUnload is just to late. The DOM is no longer present, so your script will not find a button to click.

Microsoft introduced the OnBeforeUnload event for cases like this, and as far as I know it is now supported by all major browsers.

Why do you have to call the agent in that funny matter at all?

Subject: thanks