OnWebClose Event Example

This example iterates through the open pages and, if necessary, saves them before the web is closed.

Note   To run this example, you must have at least one open web and one open page within that web. This example uses Rogue Cellars as the specified web. You can create a web called Rogue Cellars or substitute a web of your choice.

Create a form called frmLaunchEvents.frm and add two buttons, a button called cmdCloseWeb, and a button called cmdCancel. Add the following code to the Declarations section of a form code window.

Option Explicit
Private WithEvents eFPApplication As Application
Private pPage As PageWindow

Add the following code to the UserForm_Initialize section of the code window.

Private Sub UserForm_Initialize()
Set eFPApplication = New Application
End Sub

Add the following code to the cmdCloseWeb_Click section of the code window. This code sample closes the specified web.

Private Sub cmdCloseWeb_Click()
Webs("file:///C:/My Documents/My Webs/Rogue Cellars").Close
End Sub

Add the following code to the cmdCancel_Click section of the code window.

Private Sub cmdCancel_Click()
'Hide the form.
frmLaunchEvents.Hide
Exit Sub
End Sub

Add the following code to the eFPApplication_OnWebClose section of the code window. This code sample iterates through the open pages and saves them if they have been modified.

Private Sub eFPApplication_OnWebClose(ByVal pWeb As Web, _
    Cancel As Boolean)
Dim myPageWindows As PageWindows
Dim myPageWindow As PageWindow

Set myPageWindows = pWeb.ActiveWebWindow.PageWindows

For Each myPageWindow In myPageWindows
    If myPageWindow.IsDirty = True Then myPageWindow.Save
Next
End Sub