You could try something like this. This works in Access 03, not sure if any changes would be needed for 07, you'll have to consult the help to get it worked out.
Can I recommend losing the Resume and Resume Next on the error handling?Private Sub cmdReturnMTMPortfolio_Click() Dim strFile As String Dim asofDATE As String Dim txtDate As TextBox Dim fd As FileDialog Dim varFile As Variant On Error GoTo HandleErr Set fd = Application.FileDialog(msoFileDialogFilePicker) With fd .Filters.Add "Excel Files", "*.xls*" .Title = "Select MTM file to import" If .Show = -1 Then For Each varFile In .SelectedItems strFile = varFile Next varFile End If End With DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "tempMTMReportData", strFile, True, "MTM Detail!" MsgBox "Your MTM file has been imported." ExitHere: Exit Sub HandleErr: MsgBox Err & ": " & Err.Description Resume ExitHere Resume End Sub
Last edited by davegugg; 05-24-2011 at 12:33 PM.
Is your code running too slowly?
Does your workbook or database have a bunch of duplicate pieces of data?
Have a look at this article to learn the best ways to set up your projects.
It will save both time and effort in the long run!
Dave
This works, but its sloppy. I still cannot figure out a relative path.
Private Sub cmdReturnMTMPortfolio_Click() Dim appXL As Excel.Application Dim strFilePath As String Dim strFileName As String Dim strFilePrefix As String Dim strFullFileName As String Dim strFile As String Dim asofDATE As String Dim txtDate As TextBox Dim wbk As Excel.Workbook On Error GoTo HandleErr strFilePrefix = "mtm_report_asof_" strFilePath = "N:\CBI-DEPT\Application Delivery\Assignments and Projects\FCIP Program\Spreadsheet Automation\Product\Excel Automation\Robin\Communication\Portfolio List\" asofDATE = Me.txtDate.Value 'asofDATE = Format(asofDATE, "yyyymmdd") Set appXL = New Excel.Application strFullFileName = strFilePrefix & asofDATE & ".xls" Set wbk = appXL.Workbooks.Open(strFilePath & strFullFileName) DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "tempMTMReportData", strFilePath & strFullFileName, True, "MTM Detail!" DoCmd.OpenQuery "qryCPNamesForMTMDailyReportParentandChild" DoCmd.Close acQuery, "qryCPNamesForMTMDailyReportParentandChild" MsgBox "Your MTM file has been imported." ExitHere: On Error Resume Next appXL.ScreenUpdating = True appXL.Quit Set appXL = Nothing Exit Sub HandleErr: MsgBox Err & ": " & Err.Description Resume ExitHere Resume End Sub
Did you try my above solution???
Is your code running too slowly?
Does your workbook or database have a bunch of duplicate pieces of data?
Have a look at this article to learn the best ways to set up your projects.
It will save both time and effort in the long run!
Dave
I did. Thank you. Some errors came up - I did not dig and try to investigate. I have an nearly 1 week extension on this so not all is lost. I need to read up on the file dialog to see how that works in Access 2007. I have some other issues with the code so I will be posting shortly.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks