R
ryguy7272
I found this little snippet of code on the web:
Option Compare Database
Option Explicit
Function fimportAllFiles()
Dim strFileName As String
strFileName = "a" 'Need to set file name to a non-blank value so we go into
the loop.
Do While strFileName <> ""
strFileName = Dir("C:\Documents and Settings\ThinkPad\Desktop\Import\*.xls")
If strFileName <> "" Then 'A file was found
'MsgBox strFileName
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel7, "MyTable",
strFileName, True
End If
Loop
MsgBox "Done"
End Function
I tried to run it and it fails on this line:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel7, "MyTable",
strFileName, True
I was hoping to use this to import several Excel files into a few Access
Tables. I’ve used the TransferSpreadsheet method several times, always with
great success. I am just wondering if I can import data from an Excel file
into a generic Access table, without naming all the fields in the Table, but
rather letting the fields be named on the fly (automatically) as the data is
imported from Excel. Would all fields import as Text data type? Does this
violate the principle of data integrity in Access?
The reason that I ask is because I will try to get a system at work to spit
out 2, 3, or 4 Excel files, and these files may have different numbers of
records in Columns in Excel. It’s going to be hard to set up in Access
Tables in advance, with the exact Fields, if I choose slightly different
download criteria for my Excel sheets. I just wanted to get a few Excel
files, place them in a folder, and then import all the files in that folder,
each Excel files going into a different Access table. If I have to set up
generic Tables in Access, how do I do that? Just name the first Field and
use data type Text. Will Access build additional fields to accommodate all
the columns in Excel?
I’d appreciate any help with this.
Regards,
Ryan---
Option Compare Database
Option Explicit
Function fimportAllFiles()
Dim strFileName As String
strFileName = "a" 'Need to set file name to a non-blank value so we go into
the loop.
Do While strFileName <> ""
strFileName = Dir("C:\Documents and Settings\ThinkPad\Desktop\Import\*.xls")
If strFileName <> "" Then 'A file was found
'MsgBox strFileName
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel7, "MyTable",
strFileName, True
End If
Loop
MsgBox "Done"
End Function
I tried to run it and it fails on this line:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel7, "MyTable",
strFileName, True
I was hoping to use this to import several Excel files into a few Access
Tables. I’ve used the TransferSpreadsheet method several times, always with
great success. I am just wondering if I can import data from an Excel file
into a generic Access table, without naming all the fields in the Table, but
rather letting the fields be named on the fly (automatically) as the data is
imported from Excel. Would all fields import as Text data type? Does this
violate the principle of data integrity in Access?
The reason that I ask is because I will try to get a system at work to spit
out 2, 3, or 4 Excel files, and these files may have different numbers of
records in Columns in Excel. It’s going to be hard to set up in Access
Tables in advance, with the exact Fields, if I choose slightly different
download criteria for my Excel sheets. I just wanted to get a few Excel
files, place them in a folder, and then import all the files in that folder,
each Excel files going into a different Access table. If I have to set up
generic Tables in Access, how do I do that? Just name the first Field and
use data type Text. Will Access build additional fields to accommodate all
the columns in Excel?
I’d appreciate any help with this.
Regards,
Ryan---