BeforeViewSwitch Event
Occurs before the explorer changes to a new view, either as a result of user action or through program code. This event is not available in Microsoft Visual Basic Scripting Edition (VBScript).
Subobject**_BeforeViewSwitch(ByVal NewView As String, Cancel As Boolean)**
*object * An expression that evaluates to an Explorer object.
NewView Required. The name of the view the explorer is switching to.
*Cancel * Optional. False when the event occurs. If the event procedure sets this argument to True, the switch is cancelled and the current view is not changed.
Example
This Microsoft Visual Basic/Visual Basic for Applications (VBA) example confirms that the user wants to switch views and cancels the switch if the user answers No. The sample code must be placed in a class module, and the Initialize_handler
routine must be called before the event procedure can be called by Microsoft Outlook.
Dim myOlApp As New Outlook.Application
Public WithEvents myOlExp As Outlook.Explorer
Public Sub Initialize_handler()
Set myOlExp = myOlApp.ActiveExplorer
End Sub
Private Sub myOlExp_BeforeViewSwitch(ByVal NewView As Variant, Cancel As Boolean)
Dim Prompt As String
Prompt = "Are you sure you want to switch to the " & NewView & " view?"
If MsgBox(Prompt, vbYesNo + vbQuestion) = vbNo Then Cancel = True
End Sub
Applies to | Explorer Object
See Also | BeforeFolderSwitch Event | FolderSwitch Event | SelectionChange Event | Using events with Automation | ViewSwitch Event