I'm looking to make objects using a loop in VBA (and I know this might not be possible)
What I want to be able to do is put in a table name and have it make a bunch of objects (eventually I will make a class out of this whole thing with it's own methods)
I want it to get every name of the table that I type in - basically I will on launch create a class on load with all the fields of the table as public objects
whenever the database needs to update the field I can call it and use a method with ID as a parameter to update the row.
I want a standard function that builds the objects as I want to be able to create/remove fields when required without it affecting the code
I would have caveats in for the data type too (so if it is bool, int, lng etc the method behaves differently)
my code below... any ideas much appreciated
Code:
Public Function objTableSQL(TableName As String)
If IsNothing(TableName) = True Then
Exit Function
End If
Dim tableExists As Boolean
Dim strTable As String
strTable = TableName
tableExists = False
Debug.Print
Dim aDatabase As DAO.Database
Dim aTable As DAO.TableDef
Dim aField As DAO.Field
Set aDatabase = CurrentDb()
For Each aTable In aDatabase.TableDefs
If aTable.Name = strTable Then
tableExists = True
For Each aField In aTable.Fields
'create object here with name of field
Next aField
End If
Next aTable
If tableExists = False Then
Exit Function
End If
End Function