Private Sub Command28_Click()
10 On Error GoTo Command28_Clickerr
Dim fDialog As Office.FileDialog
Dim vSelected As Variant
Dim sFolder As String
Dim myquery As String
20 Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
30 With fDialog
' Set the title of the dialog box.
40 .Title = "Select Folder to Export Tables To In Excel Format"
50 .Filters.Clear
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
60 If .Show = True Then
70 For Each vSelected In .SelectedItems
80 sFolder = vSelected
90 Next vSelected
100 Else
110 MsgBox "You clicked Cancel in the file dialog box."
120 Exit Sub
130 End If
140 End With
myquery = currentrsrc
Dim qrydef As DAO.QueryDef
Dim db As DAO.Database
Set db = CurrentDb
Set qrydef = db.CreateQueryDef("tempQuery", myquery)
190 On Error Resume Next
200 Kill sFolder & "\exported.XLSX"
210 On Error GoTo Command28_Clickerr
220 DoCmd.TransferSpreadsheet acExport, , "tempQuery", sFolder & "\exported.XLSX"
230 DoCmd.RunSQL "DROP TABLE tempQuery"
240 DoEvents
250 Application.FollowHyperlink sFolder & "\exported.XLSX"
260 Exit Sub
Command28_Clickerr:
If Err.Number = 3012 Then
DoCmd.RunSQL "DROP TABLE tempQuery"
DoEvents
Resume
Else
270 MsgBox Err.Number & " " & Err.Description & " " & Erl, vbOKOnly, "Error in Command28_Clickerr"
End If
End Sub