Include datasheet sort/filter when exporting to Excel file? (1 Viewer)

Kronix

Registered User.
Local time
Today, 13:42
Joined
Nov 2, 2017
Messages
102
How can I include the sort and filter that a user has chosen in a Form's datasheet view when exporting the datasheet into an Excel file? Normally I use DoCmd.TransferSpreadsheet for the export, but that only accepts tables or queries. The sort is stored in the form's OrderBy property and the filter in the form's Filter property, so the Excel file does not have those since TransferSpreadsheet takes the query that the form is based on as a parameter, which is before the sort/filter takes place.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:42
Joined
May 7, 2009
Messages
19,246
You need to create a Query in vba with sort and filter in place. Use this query in transferspreadsheet.
 

Kronix

Registered User.
Local time
Today, 13:42
Joined
Nov 2, 2017
Messages
102
But the user is supposed to be able to change the sort and filter at will whenever they view the datasheet. One way or another, they will use the built in sort and filter and expect it to be transferred.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:42
Joined
May 7, 2009
Messages
19,246
Here is a sample of filtered export.
The idea is put the datasheet in fom as subform.
See the click event of the button.
Sort, filter as you like then export.
 

Attachments

  • FilteredExport.zip
    38.7 KB · Views: 64

Users who are viewing this thread

Top Bottom