Copy the following code to the top of the module:
Code: Select all
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWNORMAL As Long = 1
Use code like this to export and open:
Code: Select all
Sub Test()
Dim strFolder As String
Dim outputFileName As String
With Application.FileDialog(4) ' msoFileDialogFolderPicker
If .Show Then
strFolder = .SelectedItems(1)
Else
MsgBox "No folder selected!", vbExclamation
Exit Sub
End If
End With
outputFileName = strFolder & "\Export_" & Format(Date, "yyyyMMdd") & ".xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qrySummary", outputFileName, True
If ShellExecute(Application.hWndAccessApp, "Open", outputFileName, 0&, 0&, SW_SHOWNORMAL) < 33 Then
MsgBox "Couldn't open file.", vbInformation
End If
End Sub