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
Dominator1025Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
you can use the command line


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

docmd.transferspreadsheet acimport,8, "tbl1", "\\servername\sharedfolder\" & xlFile, true,"sheetName!"
0
Dominator1025Author Commented:
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?
0
Jeffrey CoachmanMIS LiasonCommented:
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
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Martin LissOlder than dirtCommented:
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
Dominator1025Author Commented:
I am still in need of an answer here.

Can Capricorn1 be messaged to answer my followup question to his reponse?
0
Rey Obrero (Capricorn1)Commented:
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"
0
Dominator1025Author Commented:
Where do those command lines get entered?   Are they part of a VBA funtion or the macro?
0
Rey Obrero (Capricorn1)Commented:
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..


.
0
Dominator1025Author Commented:
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
0
Rey Obrero (Capricorn1)Commented:
is this the name of the sheet

"Job Schedule-All" & Format(Date, "yyyymmdd") ?
0
Dominator1025Author Commented:
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.
0
Rey Obrero (Capricorn1)Commented:
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
0
Dominator1025Author Commented:
Still getting the error.
0
Rey Obrero (Capricorn1)Commented:
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
0
Dominator1025Author Commented:
Sorry, still getting the error!
0
Dominator1025Author Commented:
If it makes a difference, it is a 97-2003 workbook going to Access 2007 DB.
0
Rey Obrero (Capricorn1)Commented:
which line is giving the error?
0
Dominator1025Author Commented:
DoCmd.TransferSpreadsheet acImport, 8, "tblJobSchedule", "\\mainserver\QuotMgmt\Installs\QuotaTracker\" & xlFile, True, shtName & "!"
0
Rey Obrero (Capricorn1)Commented:
upload a copy of the Excel file.
0
Dominator1025Author Commented:
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?
0
Rey Obrero (Capricorn1)Commented:
yes..
0
Dominator1025Author Commented:
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.
0
Rey Obrero (Capricorn1)Commented:
upload the excel file..
0
Dominator1025Author Commented:
Please see attached.
Job-Schedule-All20131028.xlsx
0
Rey Obrero (Capricorn1)Commented:
omg...

try this


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

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


End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.