Importing excel to access as the results of a file search

S

scottyboy

Hi

i'm struggling with the below code, what i would like to do is to search for
the workbook "dailyfile310308.xls" and import it into access.

my problem is the filename changes and the folder changes.

so far i have..

Sub FindMaxFileandImport()
Dim iSearch As Variant
Dim iCount As Long
Dim max_file As String

max_file = "dailyfile" & Format(Date, "ddmmyy") & ".xls"
Set iSearch = Application.FileSearch

With iSearch
.LookIn = "Mypath"
.SearchSubFolders = True
.Filename = max_file
If .Execute > 0 Then
For iCount = 1 To .FoundFiles.Count
DoCmd.TransferSpreadsheet acImport, 9, "Max_csv_table",
..FoundFiles(i), True

Next iCount
Else
MsgBox "The file does not exist."
End If
End With
End Sub

help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top