R
Ronald W. Roberts
I'm writing an application that will import an Excel spreadsheet. The format
of the spreadsheet isn't
always the same, which means the Order Number isn't always in column A.
1.. The program drops or deletes the tblInput table from the collection.
2.. Imports the spreadsheet into a new tblInput.
3.. I have code that does a TabelDef and loops thru the table definition
of tblInput,
putting the field or column names into a table named tblFieldName.
4.. I then load a list box allowing the user to tell the program the Order
Number column.
Now for the problem, if I use DAO everything works fine. The columns in the
spreadsheet match column for column
the order of the tblInput table. This means the index in the collection is
in the same order as the physical columns in the spreadsheet.
If I use ADO, after the import to tblInput table, I start to load the list
box with the field names from the tblInput table.
What happens is the column or field name are returned in alphabetic order.
So what is in column 3 in the spreadsheet
is now the first column or index in the table definition.
I need to be able to load the list box in the same order as the spreadsheet
so the user doesn't get confused about which
column or field name to pick. The reason this is important is because there
is a option on my import routine that allows the user
to tell the program there are no column heading in the spreadsheet. In the
case the field name will be the default names F1, F2, F3 and so on.
Below is the code to read the table def and return the field names.
Dim cat As New ADOX.Catalog
Set cat.ActiveConnection = Application.CurrentProject.Connection
x = cat.Tables("tblInput").Columns.Count
For Y = 0 To x - 1
--Cut Code--
strName = cat.Tables("tblInput").Columns(Y).name
--Cut Code--
Next Y
An example of what is happening in ADO is
The spreadsheet
Columns Field Index
Phy Ord. Name
1 OrderNumber 0
2 LineNumber 1
3 BreakPoint 2
4 Quantity 3
After the import into tblInput, if I run the loop above, it returns the
following in alphabetic order.
Names returned from tblInput using the code above.
Field Name Index or Y
BreakPoint 0
LineNumber 1
OrderNumber 2
Quantity 3
So the question is, How do I get it to return the field names in the same
order there are in the spreadsheet?
Thanks for any help you may provide,
Ron
of the spreadsheet isn't
always the same, which means the Order Number isn't always in column A.
1.. The program drops or deletes the tblInput table from the collection.
2.. Imports the spreadsheet into a new tblInput.
3.. I have code that does a TabelDef and loops thru the table definition
of tblInput,
putting the field or column names into a table named tblFieldName.
4.. I then load a list box allowing the user to tell the program the Order
Number column.
Now for the problem, if I use DAO everything works fine. The columns in the
spreadsheet match column for column
the order of the tblInput table. This means the index in the collection is
in the same order as the physical columns in the spreadsheet.
If I use ADO, after the import to tblInput table, I start to load the list
box with the field names from the tblInput table.
What happens is the column or field name are returned in alphabetic order.
So what is in column 3 in the spreadsheet
is now the first column or index in the table definition.
I need to be able to load the list box in the same order as the spreadsheet
so the user doesn't get confused about which
column or field name to pick. The reason this is important is because there
is a option on my import routine that allows the user
to tell the program there are no column heading in the spreadsheet. In the
case the field name will be the default names F1, F2, F3 and so on.
Below is the code to read the table def and return the field names.
Dim cat As New ADOX.Catalog
Set cat.ActiveConnection = Application.CurrentProject.Connection
x = cat.Tables("tblInput").Columns.Count
For Y = 0 To x - 1
--Cut Code--
strName = cat.Tables("tblInput").Columns(Y).name
--Cut Code--
Next Y
An example of what is happening in ADO is
The spreadsheet
Columns Field Index
Phy Ord. Name
1 OrderNumber 0
2 LineNumber 1
3 BreakPoint 2
4 Quantity 3
After the import into tblInput, if I run the loop above, it returns the
following in alphabetic order.
Names returned from tblInput using the code above.
Field Name Index or Y
BreakPoint 0
LineNumber 1
OrderNumber 2
Quantity 3
So the question is, How do I get it to return the field names in the same
order there are in the spreadsheet?
Thanks for any help you may provide,
Ron