My first suggestion would be to make Field3 match the Access field types (ie. not "Numeric", but "Integer", "Long", "Double", etc.) and make Field4 the actual length. You really only need to store the length for text fields since you won't need to specify the length for the numeric datatypes.
Dim db As Database, rs As Recordset
Dim tdf As TableDef, fld As Field
Dim r As Long, nRecords As Long
Set db = CurrentDb()
rs = Openrecordset(DefinitionTableName, dbOpenDynaset)
rs.MoveLast
nRecords = rs.RecordCount
rs.MoveFirst
Set tdf = db.CreateTableDef(rs("Field1"))
For r = 1 To nRecords
if rs("Field3") = "Text" then
Set fld = tdf.CreateField(rs("Field2"), rs("Field3"), rs("Field4"))
else
Set fld = tdf.CreateField(rs("Field2"), rs("Field3"))
end if
tdf.Fields.Append fld
fld.AllowZeroLength = True
Next r
tdf.Fields.Refresh
db.TableDefs.Append tdf
db.TableDefs.Refresh
rs.Close
I realize that this code only allows for one table to be defined and there may be other things that I haven't accounted for, but I do have to leave you some things to do.
-Phil-
|