R
ryguy7272
I am using the following code to create an Access table on the fly, and
import an Excel file into the Access table that is created:
Function ImportExcelFiles()
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean
blnHasFieldNames = True
strPath = "C:\Documents and Settings\ThinkPad\Desktop\Import\"
'Name the table
strTable = "tablename"
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTable, strPathFile, blnHasFieldNames
strFile = Dir()
Loop
MsgBox "Done with Import"
End Function
Thanks Ken!! This works fine. I am now trying to figure out how to import
multiple Excel files into multiple tables. I read, in this very discussion
group that it is possible, but I can’t figure out how to actually do it. I
tried this sample code (below) and modified it a bit:
Function ImportTextFiles()
Dim strFile As String
Dim strFolder As String
Dim strTable As String
Dim strPathFile As String
Dim blnHasFieldNames As Boolean
blnHasFieldNames = False
strTable = "tablename"
strPathFile = "C:\Documents and Settings\ThinkPad\Desktop\Import\"
strFile = Dir$(strFolder & "*.xls")
Do While Len(strFile) > 0
'strPathFile = strPath & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTable, strPathFile, blnHasFieldNames
strFile = Dir$()
Loop
End Function
The code fires, but doesn’t actually do anything. What am I doing wrong?
Also, I would very much like to know how to import several .txt files into
several Access tables. I suspect it will be very, very, very similar to the
process of importing several .xls files, but since I can’t get that working,
I can’t test the process of importing several .txt files.
Any assistance would be greatly appreciated.
Regards,
Ryan---
import an Excel file into the Access table that is created:
Function ImportExcelFiles()
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean
blnHasFieldNames = True
strPath = "C:\Documents and Settings\ThinkPad\Desktop\Import\"
'Name the table
strTable = "tablename"
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTable, strPathFile, blnHasFieldNames
strFile = Dir()
Loop
MsgBox "Done with Import"
End Function
Thanks Ken!! This works fine. I am now trying to figure out how to import
multiple Excel files into multiple tables. I read, in this very discussion
group that it is possible, but I can’t figure out how to actually do it. I
tried this sample code (below) and modified it a bit:
Function ImportTextFiles()
Dim strFile As String
Dim strFolder As String
Dim strTable As String
Dim strPathFile As String
Dim blnHasFieldNames As Boolean
blnHasFieldNames = False
strTable = "tablename"
strPathFile = "C:\Documents and Settings\ThinkPad\Desktop\Import\"
strFile = Dir$(strFolder & "*.xls")
Do While Len(strFile) > 0
'strPathFile = strPath & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTable, strPathFile, blnHasFieldNames
strFile = Dir$()
Loop
End Function
The code fires, but doesn’t actually do anything. What am I doing wrong?
Also, I would very much like to know how to import several .txt files into
several Access tables. I suspect it will be very, very, very similar to the
process of importing several .xls files, but since I can’t get that working,
I can’t test the process of importing several .txt files.
Any assistance would be greatly appreciated.
Regards,
Ryan---