creating table from recordset ?

Z

Zlatko Matiæ

Hello.
How to programaticcaly create a table from a recordset ?
I tried something like this:
qryrs is recordset created by a querydef (pass-through query)...


Set tbl = db.CreateTableDef("TableNAme")

For I = 0 To qryrs.Fields.Count - 1

FieldName = qryrs.Fields(I).Name
FieldType = qryrs.Fields(I).Type
FieldSize = qryrs.Fields(I).Size

Set fld = tbl.CreateField(FieldName, FieldType, FieldSize)

' Append field to Fields collection
tbl.Fields.Append fld

Next I

' Append table to TableDef collection
db.TableDefs.Append tbl


But I have an error concerning data type of FieldType....
What is wrong ?
 
D

Douglas J. Steele

You sure the problem is the type, or might it be the size? Size doesn't
exist for most of the field types: Text is the only type where it does.
 
Z

Zlatko Matiæ

So, what to do ?

Douglas J. Steele said:
You sure the problem is the type, or might it be the size? Size doesn't
exist for most of the field types: Text is the only type where it does.
 
V

Van T. Dinh

Check whether the (source) FieldType is Text on not and use CreateField
appropriately???

I thought that was clear from Douglas' reply.
 
D

Douglas J. Steele

Well, to make it more explicit...

Set tbl = db.CreateTableDef("TableNAme")

For I = 0 To qryrs.Fields.Count - 1
FieldName = qryrs.Fields(I).Name
FieldType = qryrs.Fields(I).Type

If FieldType <> dbText Then
Set fld = tbl.CreateField(FieldName, FieldType)
Else
FieldSize = qryrs.Fields(I).Size
Set fld = tbl.CreateField(FieldName, FieldType, FieldSize)
End If

' Append field to Fields collection
tbl.Fields.Append fld

Next I
 

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