I get a daily excel file for a entire month which I want to transfer into Access at the end of the month. So, there are around 20-25 excel files I get by the end of the month, and I would like to import them into Access using a button. The data contained in the excel files is similar, so there should no formatting issues while importing.
I searched through the forums and found the code by mmccarthy for importing excel files. I tried using that code, but it keeps giving me a error message "No files found"
[CODE=vb]
Private Sub Command3_Click( )
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
Dim filename As String
Dim path As String
DoCmd.SetWarnin gs False
path = "C:\Documen ts and Settings\KK\Des ktop\Test\"
'Loop through the folder & build file list
strFile = Dir(path & "*.xls")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(int File) = strFile
strFile = Dir()
Wend
'see if any files were found
If intFile = 0 Then
MsgBox "No files found"
End If
'cycle through the list of files
For intFile = 1 To UBound(strFileL ist)
filename = path & strFileList(int File)
DoCmd.TransferS preadsheet acImport, acSpreadsheetTy peExcel3, "tblClientMail" , filename, True
Next intFile
DoCmd.SetWarnin gs True
End Sub
[/CODE]
Can someone tell me what I might be doing wrong ??
Thanks.
I searched through the forums and found the code by mmccarthy for importing excel files. I tried using that code, but it keeps giving me a error message "No files found"
[CODE=vb]
Private Sub Command3_Click( )
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
Dim filename As String
Dim path As String
DoCmd.SetWarnin gs False
path = "C:\Documen ts and Settings\KK\Des ktop\Test\"
'Loop through the folder & build file list
strFile = Dir(path & "*.xls")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(int File) = strFile
strFile = Dir()
Wend
'see if any files were found
If intFile = 0 Then
MsgBox "No files found"
End If
'cycle through the list of files
For intFile = 1 To UBound(strFileL ist)
filename = path & strFileList(int File)
DoCmd.TransferS preadsheet acImport, acSpreadsheetTy peExcel3, "tblClientMail" , filename, True
Next intFile
DoCmd.SetWarnin gs True
End Sub
[/CODE]
Can someone tell me what I might be doing wrong ??
Thanks.
Comment