Pages

Tuesday, July 26, 2011

Export The selected Row In Access table to excel

if you want to click on check boxes in access table or form then export the selected data to excel workbook.

Download the File-



Here is the code-

Option Compare Database

Private Sub Command14_Click()
' uncheck all the options
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE abc SET abc.Choose = False WHERE abc.Choose =True"
Refresh
DoCmd.SetWarnings True
End Sub

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()

' 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.OpenQuery "query1", acNormal, acEdit
DoCmd.OutputTo acOutputQuery, "query1", acFormatXLSX, Me.Text9.Value & Me.Text3.Value & Me.Combo5.Value, False
DoCmd.Close acQuery, "query1", acSaveNo
Else
' u choosed xls format
DoCmd.OpenQuery "query1", acNormal, acEdit
DoCmd.OutputTo acOutputQuery, "query1", acFormatXLS, Me.Text9.Value & Me.Text3.Value & Me.Combo5.Value, False
DoCmd.Close acQuery, "query1", acSaveNo
End If
End Sub


Access File http://www.filefactory.com/file/cc9fbbf/n/Export_Selected_data_from_access_to_excel.accdb

No comments:

Post a Comment