VBA Inserting into Table, Sorting Issue

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
Good morning,

I am facing a dilemma that I cannot solve.

When I run the following code, the Order By in the Select Statement is not respected and the data in the table is not entered in order. When I run the Select statement by its self in the "Query Designer" it shows the records in the order that we need them to be.


DoCmd.RunSQL "Insert Into [tempTrTicket-M3] " & _
"SELECT TK.PrintedName, TK.TestCode, TK.TestDescription, TK.TestDate, TK.TestTime, TK.SRC, TK.Phase, TK.Type, TK.[Student ID], TK.[First Name], TK.MI, TK.[Last Name], TK.Address, TK.City, TK.State, TK.[Zip Code], UCASE(TK.Print) As Print , TK.TicketID, TK.TicketIDLN from [AppointmentTickets-M3-Transfers-1stAppt] TK ORDER BY TK.[Last Name] ASC, TK.[First Name] ASC, TK.MI ASC"
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi it's possible there's sort order defined for the table (I find these a little confusing - but you can sort the table as you want it, then hit the "Save" button to save the "design" change to the table).

As a rule, there is no such thing as a sorted table, but in practice since I work in many of my own tables I do view data in the tables directly and have a sort order defined can be convenient. We never want end users to work with tables directly though - they can't be trusted ;)
 
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top