I am relatively new to programming. What I am trying to do is download a text file from the internet every hour, then get that into Excel, format it, save the file with the "date-time" stamp of when it downloaded, then send that sheet into an Access table. I have been able to get the Task Scheduler to kick off a generic Excel Workbook containing a macro, which then downloads the text file, and formats the data and saves the new "date-time" Excel file. The Excel VBA continues to run to get this new Excel data into Access but my problem lies in getting that data into Access. The process crashes there. The Task Scheduler gets hung up and won't run any of the process thereafter. The Excel Workbook name that Access is calling is constantly changing as it's "date-time".xlsm although the sheet with the data is the same name as I build that sheet in the formatting process. Here is what I have thus far...I am close...but not really. Perhaps there is an Access setting that needs to be changed. Perhaps the code is bad. Perhaps there is a better way to do this automatically. Any help is greatly appreciated. Thank you very much.
Code:
'So in Excel VBA...by this point in the process I have an Excel file saved automatically...the code continues below...I used double quotes to make things stand out to you...in my real code it doesn't have the double quotes except where necessary.
'This part is in Excel VBA
strPath = "FilePathOfAccessFileIncludingTheAccessFile.accdb"
strModule = "ModuleNameInAccessContainingMacroInAccess"
strMacro = "MacroNameInAccess"
strMacroArgument = "DateOfExcelFileBeingPassed"
'Function Call In Excel
Call AccessImport(strPath, strModule, strMacro, strMacroArgument)
'Function in Excel calling Access
Public Function AccessImport(strPath as string, strModule as string, strMacro as string, strMacroArgument as string)
Dim appAccess as Access.Application
Set appAccess = New Access.Application
appAccess.OpenCurrentDatabase strPath
appAccess.DoCmd.Open Module strModule, strMacro
appAccess.Run strMacro, strMacroArgument
appAccess.CloseCurrentDatabase
End Function
'At this point in the process in Excel is done and now we go to Access via VBA
Sub "MacroNameInAccess" ("DateOfExcelFileBeingPassed" as string)
Dim strPathAccess as String
Dim XLSFile as String
Let XLSFile = "DateOfExcelFileBeingPassed" & ".xlsm"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "Access Table", strPathAccess & XLSFile, True, "ExcelSheetName!"
End Sub