This gives you more features/functionality than some of the others supplied.
Option Explicit
' local collection
Private m_objFields As Collection
Public Sub Add(ByRef p_objField As clsField)
' Add the field to the local collection.
m_objFields.Add p_objField, p_objField.Name
End Sub
Public Property Get Item(ByVal p_vntIndexKey As Variant) As clsField
' Return the specified field. This can be by index or key.
' index - The caller knows the field number they want, and pass it in.
' key - The caller knows the field name they want, and pass it in.
Set Item = m_objFields(p_vntIndexKey)
End Property
Public Property Get Count() As Long
' Returns the number of fields.
Count = m_objFields.Count
End Property
Public Sub Remove(ByVal p_vntIndexKey As Variant)
' Removes the field that the called requests. See Get for info about index vs. key.
m_objFields.Remove vntIndexKey
End Sub
Public Property Get NewEnum() As IUnknown
' This is a little more complex to implement.
' 1) Add this code to your record class.
' 2) Go to the Tools Menu, and choose "Procedure Attributes...".
' The procedure attributes window will display.
' 3) Select the NewEnum entry in the Name dropdown list.
' 4) Click the Advanced button.
' The window will get bigger with more options.
' 5) In the Procedure Id combobox, type in "-4" (without the quotes).
' 6) Check the Hide This Member Checkbox.
' Returns each field in the following situation...
' For Each objField In objRecord
' {Do something with the field.}
' Next objField
Set NewEnum = m_objFields.[_NewEnum]
End Property
Private Sub Class_Initialize()
' Instantiate the collection.
Set m_objFields = New Collection
End Sub
Public Sub Clear()
' removes all the fields from the record.
Dim lngCounter As Long
For lngCounter = 1 To m_objFields.Count
m_objFields.Remove 1
End If
End Sub
Private Sub Class_Terminate()
' Destroy the collection.
If Not m_objFields Is Nothing Then
Call Clear
Set m_objFields = Nothing
End If
End Sub
John R Lick
[email protected]