Snowflake68
Registered User.
- Local time
- Today, 20:16
- Joined
- May 28, 2014
- Messages
- 464
I am having trouble exporting data in the correct sort order that is specified by the user.
I have some code that allows the user to specify the sort order of up to 6 columns that is displayed in a datasheet of a split form. Once they have sorted the data they need to be able to export the data in the same specified order.
Not all of the fields in the datasheet are required in the export so I have created a query on the table to specify which fields are needed and I needed to give some of the field names alias (as the field names in the table are not user friendly). I then use a macro to export the query (ExportWithFormatting) to an Excel file. No real issue here.
However I need to be able to tell the query to sort the data in the same sort order as the user defined on the datasheet view of the form as the two are separate objects.
Does anyone know how I can easily do this. I am pretty new to VBA and dont really understand it too much although I my system is using a lot of VBA code that I have copied and pasted from different forums and played around with it to get it to work for my purpose but that's as far as my skills allow.
I have tried so many different methods but nothing is working. The one that I thought would work is by adding some code to the OrderBy property of the query but it doesn't work and doesn't produce an error either.
This is the line I am putting in the Order By Property of the Query to tell it to use the same sort order as the form, but its not working.
[Forms]![MyFormName].[OrderBy]
Any ideas please?
I have some code that allows the user to specify the sort order of up to 6 columns that is displayed in a datasheet of a split form. Once they have sorted the data they need to be able to export the data in the same specified order.
Not all of the fields in the datasheet are required in the export so I have created a query on the table to specify which fields are needed and I needed to give some of the field names alias (as the field names in the table are not user friendly). I then use a macro to export the query (ExportWithFormatting) to an Excel file. No real issue here.
However I need to be able to tell the query to sort the data in the same sort order as the user defined on the datasheet view of the form as the two are separate objects.
Does anyone know how I can easily do this. I am pretty new to VBA and dont really understand it too much although I my system is using a lot of VBA code that I have copied and pasted from different forums and played around with it to get it to work for my purpose but that's as far as my skills allow.
I have tried so many different methods but nothing is working. The one that I thought would work is by adding some code to the OrderBy property of the query but it doesn't work and doesn't produce an error either.
This is the line I am putting in the Order By Property of the Query to tell it to use the same sort order as the form, but its not working.
[Forms]![MyFormName].[OrderBy]
Any ideas please?