List of fields in a table (2nd try)

S

SBD

Thanks for your response Duane, but I think I need to give
more details here.

I'm working on a routine that will allow importing data
from an external file into another table. The problem is
that the data to be imported is variable. We will not
always get the same layout or even file type. So what I'm
trying to do is basically build a wizard that will allow
the user to select the fields from the imported file and
map them to the fields on the main table.

My first step is to create a link to the import file. My
next step (as I see it) is to display a list of the fields
in the linked and main tables and have the user assign a
number (the same #) to the corresponding fields on each
side.

I already have the list of fields for the main table, but
I need to create a list for the imported file after the
file is linked and I need to know how.

Unless someone else has a similar routine they wish to
share I would appreciate some direction on this.

Scott<>
 
T

Tim Ferguson

I already have the list of fields for the main table, but
I need to create a list for the imported file after the
file is linked and I need to know how.
I don't think you can put a UDT into a collection, so the way I would do it
is to create a Class that holds the field type, size, properties and so on,
and then manage a Collection of them, vis:

For Each fdl in tdfImportedTableDef
' empty the object
Set fo = New CFieldObject

' read the data type
fo.GetInfoFrom fld

' add it to the collection
collFields.Add fld.Name, fo

Next fld

You could use the same structures for parsing a text csv file or an Excel
sheet and so on. Hope that helps


Tim F
 
S

SBD

Tim,
Whoa, a bit over my head. I vaguely understand the
concepts, but you lost me on the execution. I'm not clear
on a few points:

a) how do I define tdfImportedTableDef? The process I have
creates a linked table named "CurrentLink" after the user
selects the file to be imported.

b) How is "fo" defined?

c) How is collfields defined?

I've actually got about 75% of this working and this piece
represents most of the missing 25%.
 
T

Tim Ferguson

a) how do I define tdfImportedTableDef? The process I have
creates a linked table named "CurrentLink" after the user
selects the file to be imported.

Hmmm: it should actually have been tdfImportedTableDef.Fields because the
idea is to create a link to the original table (wherever or whatever it is)
by creating a TableDef object, and then iterating through its Fields
collection. The actual process would be something along the lines of this,
although be warned that this has come off the top of my head and is not
tested:-

' create an empty tdf object
Dim tdfImportedTableDef as TableDef
Set tdfImportedTableDef = db.CreateTableDef("TempLink")

' link it to the source
tdfImportedTableDef.Connect = "dBase IV;DATABASE=C:\dBASE\Samples"

' append it into the current database
db.TableDefs.Append tdfImportedTableDef
b) How is "fo" defined?

Dim fo as CFieldObject

but you'd have to create the Class module yourself, according to what you
want to be able to do.
c) How is collfields defined?

Dim collFields as Collection

which is the easy version.

Hope that helps


Tim F
 

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