Visual Basic for Applications Reference

RaiseEvent Statement

See Also Example Specifics

Fires an event declared at module level within a class, form, or document.

Syntax

RaiseEventeventname [(argumentlist)]

The required eventname is the name of an event declared within the module and follows Basic variable naming conventions.

The RaiseEvent statement syntax has these parts:

Part Description
eventname Required. Name of the event to fire.
argumentlist Optional. Comma-delimited list of variables, arrays, or expressions The argumentlist must be enclosed by parentheses. If there are no arguments, the parentheses must be omitted.

Remarks

If the event has not been declared within the module in which it is raised, an error occurs. The following fragment illustrates an event declaration and a procedure in which the event is raised.

' Declare an event at module level of a class module
Event LogonCompleted (UserName as String)

Sub
   ' Raise the event.
   RaiseEvent LogonCompleted ("AntoineJan")
End Sub

If the event has no arguments, including empty parentheses, in the RaiseEvent, invocation of the event causes an error. You can't use RaiseEvent to fire events that are not explicitly declared in the module. For example, if a form has a Click event, you can't fire its Click event using RaiseEvent. If you declare a Click event in the form module, it shadows the forms own Click event. You can still invoke the forms Click event using normal syntax for calling the event, but not using the RaiseEvent statement.

Event firing is done in the order that the connections are established. Since events can have ByRef parameters, a process that connects late may receive parameters that have been changed by an earlier event handler.