RaiseEvent Statement
Use the RaiseEvent statement to signal a declared event in a class module.
Syntax
RaiseEvent eventname [(<arguments>)]
where <arguments> is
{ <expression> },...
Notes
You must always declare an event in the class module that raises the event. You cannot use RaiseEvent to signal a built-in event (such as Current) of a form or report class module. If an event passes no arguments, you must not include an empty pair of parentheses when you code the RaiseEvent statement. An event can be received only by another module that has declared an object variable using WithEvents that has been set to the class module or object containing this class.
Example
To define an event named Signal that returns a text string and then to signal that event in a class module, enter the following:
Option Explicit Public Event Signal(ByVal strMsg As String) Public Sub RaiseSignal(ByVal strText As String) RaiseEvent Signal(strText) End Sub
Select Case Statement
Use a Select Case statement to execute statements conditionally based on the evaluation of an expression that is compared to a list or range of values.
Syntax
Select Case <test expression> [Case <comparison list 1> [<procedure statements 1>]] ... [Case Else [<procedure statements n>]] End Select
where <test expression> is any numeric or string expression; where <comparison list> is
{<comparison element>,...}
where <comparison element> is
{expression | expression To expression | Is <comparison operator> expression}
and where <comparison operator> is
{= | <> | < | > | <= | >=}
Notes
If the <test expression> matches a <comparison element> in a Case clause, Visual Basic executes the statements that follow that clause. If the <comparison element> is a single expression, the <test expression> must equal the <comparison element> for the statements following that clause to execute. If the <comparison element> contains a To keyword, the first expression must be less than the second expression (either in numeric value if the expressions are numbers or in collating sequence if the expressions are strings) and the <test expression> must be between the first expression and the second expression. If the <comparison element> contains the Is keyword, the evaluation of <comparison operator> expression must be true.
If more than one Case clause matches the <test expression>, Visual Basic executes only the set of statements following the first Case clause that matches. You can include a block of statements following a Case Else clause that Visual Basic executes if none of the previous Case clauses matches the <test expression>. You can nest another Select Case statement within the statements following a Case clause.
Example
To assign an integer value to a variable, depending on whether a string begins with a letter from A through F, from G through N, or from O through Z, enter the following:
Dim strMyString As String, intVal As Integer Select Case UCase$(Mid$(strMyString, 1, 1)) Case "A" To "F" intVal = 1 Case "G" To "N" intVal = 2 Case "O" To "Z" intVal = 3 Case Else intVal = 0 End Select
In this tutorial:
- Visual Basic Fundamentals
- Visual Basic Development Environment
- Visual Basic Editor Window
- Relationship Between Access and Visual Basic
- Visual Basic Debugging Tools
- Working with the Watch Window
- Variables and Constants
- Variable and Constant Scope
- Declaring Constants and Variables
- Dim Statement
- Enum Statement
- Event Statement
- Private Statement
- Public Statement
- Static Statement
- Type Statement
- Collections, Objects, Properties, and Methods
- DAO Architecture
- ADO Architecture
- Referencing Collections, Objects, and Properties
- Use Exclamation Points and Periods
- Assigning an Object Variable-Set Statement
- Object Methods
- Manipulating Complex Data Types Using DAO
- Working with ADO Recordsets
- Functions and Subroutines
- Sub Statement
- Understanding Class Modules
- Property Let
- Property Set
- Controlling the Flow of Statements
- Do...Loop Statement
- For...Next Statement
- For Each...Next Statement
- If...Then...Else Statement
- RaiseEvent Statement
- Stop Statement
- With...End Statement
- Running Macro Actions and Menu Commands
- Executing an Access Command
- Trapping Errors
- Working with 64-Bit Access Visual Basic for Applications
- Using LongPtr Data Types
- Supporting Older Versions of Access
- Using LongLong Data Types