Private Sub MasterExport_Click()
Call ExportTable("MasterQuery")
End Sub
Sub ExportTable(TableName As String)
Dim FileName As String
FileName = ChooseXLFile
If FileName <> "" Then
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, TableName, FileName, True
End If
End Sub
Function ChooseXLFile() As Variant
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
Dim varDirectory As String, varTitleForDialog As String
' Don't change directories when done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
lngFlags = ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR
varDirectory = ""
varTitleForDialog = "Please specify a file to save (*.xls)"
' Define the filter string and allocate space in the "c"
' string.
strFilter = ahtAddFilterItem(strFilter, "Excel (*.xls)", "*.xls")
' Now actually call to get the file name.
varFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
InitialDir:=varDirectory, _
Filter:=strFilter, _
flags:=lngFlags, _
DialogTitle:=varTitleForDialog)
If Not IsNull(varFileName) Then
varFileName = TrimNull(varFileName)
End If
ChooseXLFile = varFileName
End Function
DoCmd.TransferSpreadsheet acExport, 10, "Queryname", "C:\PathAndFileName.xlsx"