Link to home
Start Free TrialLog in
Avatar of Dominator1025
Dominator1025

asked on

How to Automatically import a daily Excel file to an Access table as the Excel file is added

Hello Experts,

I have been tasked with creating a daily report.  I would like to automate the entire process, if possible.  I'm talking about not touching it at all once it is set up!  If guided, I am fairly comfortable using macros and VBA.

Here is my 1st question of 4 at this point:
I would like my Access database to automatically import an excel file to tbl1 as the file is published daily to a server folder. The file names are date based (Report100313.xls, Report100413.xls, etc).  

Thanks,
Dominick
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

you can use the command line


xlFile="Report100" & format(Date(),"dyy") & ".xls"

docmd.transferspreadsheet acimport,8, "tbl1", "\\servername\sharedfolder\" & xlFile, true,"sheetName!"
Avatar of Dominator1025
Dominator1025

ASKER

Thanks Cap -

Where would I enter that command?

If the network path has 30 files for each day of the month, will that command tell it to pick today's file?

Is there a way to have access do that all on it's own over our network? Or would I need to have a machine running with some sort of scheduler for that? If a machine with a scheduler is needed, what would you recommend?
Doing anything from a scheduled task is tricky, and not easy to explain if you have never done it before...

To sketch the broad strokes:
Create a function to import the file based on the day
Create a macro to run this function
Create a scheduled task in windows
The command to execute the macro in the DB will be something like this:
c:\YourPathToYourAccessExecutable\MSAccess.exe c:\YourFolder\yourDatabase.mdb /YourMacro

JeffCoachman
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
I am still in need of an answer here.

Can Capricorn1 be messaged to answer my followup question to his reponse?
this line, tells you to get the file for the current date

xlFile="Report100" & format(Date(),"dyy") & ".xls"

it will be better to include the month

xlFile="Report100" & format(Date(),"dmmyy") & ".xls"
Where do those command lines get entered?   Are they part of a VBA funtion or the macro?
try placing the codes in the click event of a button in a form to test...

you can also place the codes in a regular module as a function

function ImportExcelFile()
xlFile="Report100" & format(Date(),"dyy") & ".xls"

docmd.transferspreadsheet acimport,8, "tbl1", "\\servername\sharedfolder\" & xlFile, true,"sheetName!"

end function

you can then call the function in a macro with

Action
Runcode



Function name ImportExcelFile()


you can run the macro by using a .bat file and task scheduler..


.
Any idea why I am getting a run time error 3011 with this code?

Function ImportExcelFile()
xlFile = "Job Schedule-All" & Format(Date, "yyyymmdd")  & ".xls"

DoCmd.TransferSpreadsheet acImport, 8, "tblJobSchedule", "\\mainserver\QuotMgmt\Installs\QuotaTracker\" & xlFile, True, "Job Schedule-All" & Format(Date, "yyyymmdd")

End Function
is this the name of the sheet

"Job Schedule-All" & Format(Date, "yyyymmdd") ?
The name of the sheet is dynamic with the date just the same as the file name. I tried it with just the names of the sheet instead of trying to use the format(date code and I got the error just the same.
try this

Function ImportExcelFile()
dim xlFile as string
xlFile = "Job Schedule-All" & Format(Date, "yyyymmdd")  & ".xls"

DoCmd.TransferSpreadsheet acImport, 8, "tblJobSchedule", "\\mainserver\QuotMgmt\Installs\QuotaTracker\" & xlFile, True, xlFile & "!"

End Function
Still getting the error.
oops sorry, try this one

Function ImportExcelFile()
Dim xlFile As String, shtName
xlFile = "Job Schedule-All" & Format(Date, "yyyymmdd") & ".xls"
shtName = "Job Schedule-All" & Format(Date, "yyyymmdd")

DoCmd.TransferSpreadsheet acImport, 8, "tblJobSchedule", "\\mainserver\QuotMgmt\Installs\QuotaTracker\" & xlFile, True, shtName & "!"


End Function
Sorry, still getting the error!
If it makes a difference, it is a 97-2003 workbook going to Access 2007 DB.
which line is giving the error?
DoCmd.TransferSpreadsheet acImport, 8, "tblJobSchedule", "\\mainserver\QuotMgmt\Installs\QuotaTracker\" & xlFile, True, shtName & "!"
upload a copy of the Excel file.
It is all sensitive customer information that I cannot share.  If I delete all of the fields in the file then save as a new copy with the same format, will that work?
I had a breakthrough.  There was a space at the end of the file name and at the end of the sheet name. I added the & " "  and now I am getting run time error 3274 that says external table is not in the expected format.
upload the excel file..
Please see attached.
Job-Schedule-All20131028.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial