This code works, but I want to populate an array at a modular level so that other routines can take advantage of it.
I have tried something like this at the top of the module
This declaration is at the top of the same module in which I writing the code. I have changed the routine as follows.
When I reach this line "marrFNames(i).BDFieldName = f.name", I get an object required message.
Any insights will be appreciated.
Code:
Sub FindBDFieldNames(strTableName As String)
'By convention the last two digits of tables that have balances due are "BD".
'We want to loop through a table and discover each of these fields.
On Error GoTo err_FFN
Dim rst As DAO.Recordset
Dim f As Field
Dim i As Integer
Dim iLoop As Integer
Set rst = CurrentDb.OpenRecordset(strTableName)
For Each f In rst.Fields
If Right(f.name, 2) = "BD" Then
i = i + 1
ReDim arrFNames(i) As BDFieldNames
MsgBox f.name
arrFNames(i).BDFieldName = f.name
arrFNames(i).Entered = False
'ReDim Preserve marrFieldNames(0 To i) As BDFieldNames
Debug.Print (i & " - " & arrFNames(i).BDFieldName & " - " & arrFNames(i).Entered)
rst.MoveNext
End If
Next f
rst.Close
Exit Sub
err_FFN:
ErrBox "finding field names and populating an array with them in FindBDFieldNames"
End Sub
I have tried something like this at the top of the module
Code:
Dim marrBDFNames As BDFieldNames
This declaration is at the top of the same module in which I writing the code. I have changed the routine as follows.
Code:
Sub ProcessBDFieldNames(strTableName As String)
'By convention the last two digits of tables that have balances due are "BD".
'We want to loop through a table and discover each of these fields.
On Error GoTo err_FFN
Dim rst As DAO.Recordset
Dim f As Field
Dim i As Integer
Dim iLoop As Integer
Set rst = CurrentDb.OpenRecordset(strTableName)
For Each f In rst.Fields
If Right(f.name, 2) = "BD" Then
i = i + 1
ReDim marrFNames(i)
MsgBox f.name
marrFNames(i).BDFieldName = f.name
marrFNames(i).Entered = False
'ReDim Preserve marrFieldNames(0 To i) As BDFieldNames
Debug.Print (i & " - " & marrFNames(i).BDFieldName & " - " & marrFNames(i).Entered)
rst.MoveNext
End If
Next f
rst.Close
Exit Sub
err_FFN:
ErrBox "finding field names and populating an array with them in FindBDFieldNames"
End Sub
Any insights will be appreciated.