order records by a certain field

dd/mm/yy

Registered User.
Local time
Today, 11:47
Joined
Mar 19, 2004
Messages
14
hi there

on a system i have i have an order entry form where there are two important fields- OrderID and CustomerID. I am using an SQL statement to pull the values into the form from the different tables. the problem however is that the form is showing records sorted by CustomerID as opposed to OrderID.

here is my sql statement in the forms data source:

SELECT tblOrders.OrderID, tblOrders.CustomerID, tblOrders.DateOpened, tblCustomers.CustomerName FROM tblOrders INNER JOIN tblCustomers ON tblOrders.CustomerID=tblCustomers.CustomerID;

I thought this may be the cause of it but after playing around with it i cant make it sort by OrderID. OrderID is the primary key of tblOrders and the CustomerID field is simply linked to the primary key of tblCustomers, so I cant understand why its not sorting by the primary key.

I have tried the OrderBy field in the form properties but cant seem to make this work....

anyone have any ideas how to switch this to sort by OrderID? :confused:

thanks in advance

dd/mm/yy
 
This should do it

SELECT tblOrders.OrderID, tblOrders.CustomerID, tblOrders.DateOpened, tblCustomers.CustomerName FROM tblOrders INNER JOIN tblCustomers ON tblOrders.CustomerID=tblCustomers.CustomerID ORDER BY tblOrders.OrderID;

HTH
 
hey thanks! didnt know you could use OrderBy in the SQL statement - thought you had to use the property. stil learning! :rolleyes:

thanks again

dd/mm/yy :D
 

Users who are viewing this thread

Back
Top Bottom