Hi, Im trying to make a table using fields names, type, and size listed in another table named FileLayout. I get Type Conversion Error on the line where I create the fieldtype. Should I use something instead of String??
Function CreateTable()
Dim db As Database
Dim rs As DAO.Recordset
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim dsp As String, fldname As String, fldtype, fldsize As Integer
Dim prp As DAO.Property
Dim sqlstr As String
Dim newtable As String
newtable = InputBox("Enter New table Name")
'Open Database
sqlstr = "select * from Filelayout;"
Set db = CurrentDb
Set rs = db.OpenRecordset(sqlstr)
Set tdf = db.CreateTableDef(newtable)
With tdf
rs.MoveFirst
While Not rs.EOF
fldname = rs.Fields("FieldName")
fldtype = rs.Fields("FieldType")
fldsize = rs.Fields("FieldSize")
.Fields.Append .CreateField(fldname, fldtype, fldsize)
rs.MoveNext
Wend
End With
'Close Database
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Function
Function CreateTable()
Dim db As Database
Dim rs As DAO.Recordset
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim dsp As String, fldname As String, fldtype, fldsize As Integer
Dim prp As DAO.Property
Dim sqlstr As String
Dim newtable As String
newtable = InputBox("Enter New table Name")
'Open Database
sqlstr = "select * from Filelayout;"
Set db = CurrentDb
Set rs = db.OpenRecordset(sqlstr)
Set tdf = db.CreateTableDef(newtable)
With tdf
rs.MoveFirst
While Not rs.EOF
fldname = rs.Fields("FieldName")
fldtype = rs.Fields("FieldType")
fldsize = rs.Fields("FieldSize")
.Fields.Append .CreateField(fldname, fldtype, fldsize)
rs.MoveNext
Wend
End With
'Close Database
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Function