Visual Basic for Applications Reference

Type Statement Example

This example uses the Type statement to define a user-defined data type. The Type statement is used at the module level only. If it appears in a class module, a Type statement must be preceded by the keyword Private.

  
    
      Type
     EmployeeRecord   ' Create user-defined type.
   ID As Integer   ' Define elements of data type.
   Name As String * 20
   Address As String * 30
   Phone As Long
   HireDate As Date
End Type
Sub CreateRecord()
   Dim MyRecord As EmployeeRecord   ' Declare variable.

   ' Assignment to EmployeeRecord variable must occur in a procedure.
   MyRecord.ID = 12003   ' Assign a value to an element.
End Sub