G
Guest
The Excel file I have to import is generated automatically by QuickBooks so I
have no control over the format, etc., it comes out in. That said, I have
(at least) two problems importing this data.
1) I need to use the first row of Excel data as column names in my imported
table -- except not all the fields in the first row have data in them. Is
this a potential problem?
To create the necessary table to import the Excel data into, I created a
table ("Imported_RawData") using:
Dim col As ADOX.Column
col.Name = "Field1"
col.Type = adVarWChar
col.DefinedSize = 100
col.Attributes = 0
Set col.ParentCatalog = cat
tbl.Columns.Append col
etc...
I use "Field1", etc., as column names for all the empty fields in the 1st
row of the Excel file, and the text names otherwise. When I run the code for
creating the table, all looks fine. However...
2) After the 1st row of data in the Excel file, each subsequent field of
each column is itself either blank or text or number or date, etc. And when
I run the following code, I get a Run-time error '13' type mismatch:
Dim stDocName As String
stDocName = "C:\Data\RawData.xls"
DoCmd.TransferSpreadsheet acImport, "Imported_RawData", stDocName, True,
"Sheet1$"
The frustrating part of this is that when I manually import the table with
the wizard, the data comes into Access perfectly! But using this manual
import is not an option for the application, unfortunately. Is there a way
to automate the wizard process in VBA or any other (non-manual) way to get
this data into Access?
Thank you very much for any suggestions!
have no control over the format, etc., it comes out in. That said, I have
(at least) two problems importing this data.
1) I need to use the first row of Excel data as column names in my imported
table -- except not all the fields in the first row have data in them. Is
this a potential problem?
To create the necessary table to import the Excel data into, I created a
table ("Imported_RawData") using:
Dim col As ADOX.Column
col.Name = "Field1"
col.Type = adVarWChar
col.DefinedSize = 100
col.Attributes = 0
Set col.ParentCatalog = cat
tbl.Columns.Append col
etc...
I use "Field1", etc., as column names for all the empty fields in the 1st
row of the Excel file, and the text names otherwise. When I run the code for
creating the table, all looks fine. However...
2) After the 1st row of data in the Excel file, each subsequent field of
each column is itself either blank or text or number or date, etc. And when
I run the following code, I get a Run-time error '13' type mismatch:
Dim stDocName As String
stDocName = "C:\Data\RawData.xls"
DoCmd.TransferSpreadsheet acImport, "Imported_RawData", stDocName, True,
"Sheet1$"
The frustrating part of this is that when I manually import the table with
the wizard, the data comes into Access perfectly! But using this manual
import is not an option for the application, unfortunately. Is there a way
to automate the wizard process in VBA or any other (non-manual) way to get
this data into Access?
Thank you very much for any suggestions!