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
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
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?
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:\YourPathToYourAccessExe cutable\MS Access.exe c:\YourFolder\yourDatabase .mdb /YourMacro
JeffCoachman
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:\YourPathToYourAccessExe
JeffCoachman
I've requested that this question be deleted for the following reason:
Not enough information to confirm an answer.
Not enough information to confirm an answer.
ASKER
I am still in need of an answer here.
Can Capricorn1 be messaged to answer my followup question to his reponse?
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"
xlFile="Report100" & format(Date(),"dyy") & ".xls"
it will be better to include the month
xlFile="Report100" & format(Date(),"dmmyy") & ".xls"
ASKER
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..
.
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
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..
.
ASKER
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\Ins talls\Quot aTracker\" & xlFile, True, "Job Schedule-All" & Format(Date, "yyyymmdd")
End Function
Function ImportExcelFile()
xlFile = "Job Schedule-All" & Format(Date, "yyyymmdd") & ".xls"
DoCmd.TransferSpreadsheet acImport, 8, "tblJobSchedule", "\\mainserver\QuotMgmt\Ins
End Function
is this the name of the sheet
"Job Schedule-All" & Format(Date, "yyyymmdd") ?
"Job Schedule-All" & Format(Date, "yyyymmdd") ?
ASKER
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\Ins talls\Quot aTracker\" & xlFile, True, xlFile & "!"
End Function
Function ImportExcelFile()
dim xlFile as string
xlFile = "Job Schedule-All" & Format(Date, "yyyymmdd") & ".xls"
DoCmd.TransferSpreadsheet acImport, 8, "tblJobSchedule", "\\mainserver\QuotMgmt\Ins
End Function
ASKER
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\Ins talls\Quot aTracker\" & xlFile, True, shtName & "!"
End Function
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\Ins
End Function
ASKER
Sorry, still getting the error!
ASKER
If it makes a difference, it is a 97-2003 workbook going to Access 2007 DB.
which line is giving the error?
ASKER
DoCmd.TransferSpreadsheet acImport, 8, "tblJobSchedule", "\\mainserver\QuotMgmt\Ins talls\Quot aTracker\" & xlFile, True, shtName & "!"
upload a copy of the Excel file.
ASKER
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?
yes..
ASKER
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..
ASKER
Please see attached.
Job-Schedule-All20131028.xlsx
Job-Schedule-All20131028.xlsx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
xlFile="Report100" & format(Date(),"dyy") & ".xls"
docmd.transferspreadsheet acimport,8, "tbl1", "\\servername\sharedfolder