Pages

Showing posts with label Export Selected Query From Access to Excel. Show all posts
Showing posts with label Export Selected Query From Access to Excel. Show all posts

Tuesday, August 2, 2011

Export Selected Query From Access to Excel

If you want to export the query to excel .Snapshot below-



Here is the code-

Option Compare Database

Private Sub Command2_Click()
Dim fldpth As String
'it will open the dialogbox and choose folder in which all workbooks are saved.
Application.FileDialog(msoFileDialogFolderPicker).Title = "Choose Folder"
Application.FileDialog(msoFileDialogFolderPicker).Show
fldpth = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\"
Me.Text9.Value = fldpth
End Sub

Private Sub Command7_Click()

' SELECT [Name] FROM MsysObjects WHERE [Type]=5 And Left([Name],1)<>"~" ORDER BY [Name]; to combo box to list all saved queries in database
' it will open the query1 which is saved in the access database run it and export its output to excel workbook.
If Me.Combo5.Value = ".xlsx" Then
' when you choose xlsx format
DoCmd.OutputTo acOutputQuery, Me.Combo15.Value, acFormatXLSX, Me.Text9.Value & Me.Text3.Value & Me.Combo5.Value, False
Else
' u choosed xls format
DoCmd.OutputTo acOutputQuery, Me.Combo15.Value, acFormatXLS, Me.Text9.Value & Me.Text3.Value & Me.Combo5.Value, False
End If
End Sub


Access Macro File - http://www.filefactory.com/file/cdccf47/n/Export_Selected_Access_Query_To_Excel.accdb