Makai
Makai

Reputation: 617

VBA Data Type within another Data Type

I am trying to us a Type within another type but it is not letting me.

Public Type MyTable
     Name As String
     IDStartingNumber As Integer
     Items(50) As MyItem
End Type

Public Type MyItem
    Name As String
    DataType As DataTypes
    Number As Integer
    AllowNull As Boolean
    Unique As Boolean
    Reference As MyTable
End Type

What is going on and how do I fix this?

Upvotes: 0

Views: 785

Answers (2)

SlartyBartFast
SlartyBartFast

Reputation: 1

In both examples, it appears one type references the other, so neither example should work.

i.e.

Public Type MyTable Name As String IDStartingNumber As Integer Items(50) As MyItem End Type

Public Type MyItem Name As String DataType As DataTypes Number As Integer AllowNull As Boolean Unique As Boolean Reference As MyTable End Type

You cannot have one type refer to a different type which refers back to the first type.

Upvotes: 0

dennythecoder
dennythecoder

Reputation: 772

Make sure the type you're referencing is before it. In your example you have the MyItem type afterwards. For example:

Public Type MyItem
    Name As String
    DataType As DataTypes
    Number As Integer
    AllowNull As Boolean
    Unique As Boolean
    Reference As MyTable
End Type

Public Type MyTable
     Name As String
     IDStartingNumber As Integer
     Items(50) As MyItem
End Type

Upvotes: 6

Related Questions