Create Table

C

Craig

Having issues with this. Get an datatype conversion error on the
'createfield' line. Doesn't seem to like the rs("Type") or rs("Size").
However, these values are being pulled from another table (Damages) and are
legitimate values (ie, dbText, etc.).

Also, is there a better way to create a table (maybe SQL syntax)?? Thanks
for any help.

Sub Createtable()
Dim tdfNew As TableDef
Dim db As Database
Dim rs As Recordset
Dim intCount As Integer
Set db = CurrentDb()
' Create a new TableDef object.
Set tdfNew = db.CreateTableDef("tblDamage")
Set rs = db.OpenRecordset("Damages")
intCount = rs.RecordCount
rs.MoveFirst
'
With tdfNew
For i = 1 To intCount
.Fields.Append .CreateField(rs("Name"), rs("Type"), rs("Size"))
rs.MoveNext
Next i
' Append the new TableDef object
db.TableDefs.Append tdfNew
End With
'
rs.Close
Set db = Nothing
'
End Sub
 
B

Brendan Reynolds

If you are trying to create a text field, you should be assigning the
numeric value 10 to the Type property, 10 being the value of the intrinsic
constant named dbText. As it is a numeric value, it should not have any
quotes around it.

If you can't change that table to return the numeric values of the constants
instead of their names, the best solution would probably be to create a new
table with both the names and the values, and then join it to the old table
in a query. You can then retrieve the numeric value from the query.
 
C

Craig

Thanks...
--
Craig


Brendan Reynolds said:
If you are trying to create a text field, you should be assigning the
numeric value 10 to the Type property, 10 being the value of the intrinsic
constant named dbText. As it is a numeric value, it should not have any
quotes around it.

If you can't change that table to return the numeric values of the constants
instead of their names, the best solution would probably be to create a new
table with both the names and the values, and then join it to the old table
in a query. You can then retrieve the numeric value from the query.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top