I have not been able to figure out what I need to get to the individual entries in a collection. I have the For Each loop, but the code stops at Debug.Print Item.FieldName. The following is the code. I'm looking for how to do this so it will work. Thanks! The error message is: "Object doesn't support this property or method" Run=time error '438'
Code:
Sub ShowFields()
Dim Item As Variant
For Each Item In cAddPermits
Debug.Print Item.FieldName
Next Item
End Sub
Here is the code for the two classes used here. (cFieldName)
Code:
Option Compare Database
Option Explicit
Dim mFieldName As String
Public Property Get FieldName() As String
FieldName = mFieldName
End Property
Public Property Let FieldName(newFieldName As String)
mFieldName = newFieldName
End Property
And then cFieldNames
Code:
Option Compare Database
Option Explicit
Private mPrivateCollection As Collection
' Add a new cFieldName item to the collection
Public Function Add(FieldName As String) As cFieldName
Dim newItem As New cFieldName
Dim Key As Variant
newItem.FieldName = FieldName
Key = FieldName
'add to the private collection
mPrivateCollection.Add newItem, Key ', FieldName
Set Add = newItem
ExitFunction:
Set newItem = Nothing
Exit Function
End Function
And finally, the routine that fills the collection
Code:
Option Compare Database
Option Explicit
Public cAddPermits As cFieldNames
Sub FillAddPermits()
Set cAddPermits = New cFieldNames
cAddPermits.ClassInitialize
cAddPermits.Add "PermitType"
cAddPermits.Add "FiscalYearID"
End Sub