Solved

'Order By' Statement in MS Access V2.0 -- HELP

Posted on 1998-02-23
1
198 Views
Last Modified: 2006-11-17
Hello,

I need some help,

Please Examine the Two Pieces of SQL (The Order By part mainly)

This Works

Start Of SQL
SELECT DISTINCTROW Quote.Date, Quote.Initails, Quote.[Estimate No],
Quote.[Company Name], Quote.[Contact Name], Quote.[Job Description],
Quote.[% Rate], Quote.[Value £], Quote.Status
FROM Quote
WHERE (
( (([Forms]![Query Menu]![From Date] = NULL) AND ([Forms]![Query
Menu]![To Date] = NULL) )
OR
(Quote.Date Between [Forms]![Query Menu]![From Date] And
[Forms]![Query Menu]![To Date]))
AND
(([Forms]![Query Menu]![Initails] = NULL) OR
(Quote.Initails=[Forms]![Query Menu]![Initails]))
AND
(([Forms]![Query Menu]![Contact Name] = NULL) OR ([Quote]![Contact
Name] LIKE [Forms]![Query Menu]![Contact Name]))
AND
(([Forms]![Query Menu]![Company Name] = NULL) OR ([Quote]![Company
Name] LIKE [Forms]![Query Menu]![Company Name]))
AND
( (([Forms]![Query Menu]![From %] = NULL) AND ([Forms]![Query
Menu]![To %] = NULL) )
OR
([Quote]![% Rate] Between [Forms]![Query Menu]![From %] And
[Forms]![Query Menu]![To %]))
AND
( (([Forms]![Query Menu]![From Value] = NULL) AND ([Forms]![Query
Menu]![To Value] = NULL) )
OR
([Quote]![Value £] Between [Forms]![Query Menu]![From Value] And
[Forms]![Query Menu]![To Value]))
AND
(([Forms]![Query Menu]![Estimate No] = NULL) OR ([Quote]![Estimate No]
LIKE [Forms]![Query Menu]![Estimate No]))
AND
(([Forms]![Query Menu]![Status] = NULL) OR ([Quote]![Status] =
[Forms]![Query Menu]![Status]))

)
ORDER BY Quote.Initails;
End Of SQL




This Does Not Work (Even Though [Forms]![Query Menu]![Sort By]
="Quote.Initails") This is a value list listing all Fields


Start of SQL
SELECT DISTINCTROW Quote.Date, Quote.Initails, Quote.[Estimate No],
Quote.[Company Name], Quote.[Contact Name], Quote.[Job Description],
Quote.[% Rate], Quote.[Value £], Quote.Status
FROM Quote
WHERE (
( (([Forms]![Query Menu]![From Date] = NULL) AND ([Forms]![Query
Menu]![To Date] = NULL) )
OR
(Quote.Date Between [Forms]![Query Menu]![From Date] And
[Forms]![Query Menu]![To Date]))
AND
(([Forms]![Query Menu]![Initails] = NULL) OR
(Quote.Initails=[Forms]![Query Menu]![Initails]))
AND
(([Forms]![Query Menu]![Contact Name] = NULL) OR ([Quote]![Contact
Name] LIKE [Forms]![Query Menu]![Contact Name]))
AND
(([Forms]![Query Menu]![Company Name] = NULL) OR ([Quote]![Company
Name] LIKE [Forms]![Query Menu]![Company Name]))
AND
( (([Forms]![Query Menu]![From %] = NULL) AND ([Forms]![Query
Menu]![To %] = NULL) )
OR
([Quote]![% Rate] Between [Forms]![Query Menu]![From %] And
[Forms]![Query Menu]![To %]))
AND
( (([Forms]![Query Menu]![From Value] = NULL) AND ([Forms]![Query
Menu]![To Value] = NULL) )
OR
([Quote]![Value £] Between [Forms]![Query Menu]![From Value] And
[Forms]![Query Menu]![To Value]))
AND
(([Forms]![Query Menu]![Estimate No] = NULL) OR ([Quote]![Estimate No]
LIKE [Forms]![Query Menu]![Estimate No]))
AND
(([Forms]![Query Menu]![Status] = NULL) OR ([Quote]![Status] =
[Forms]![Query Menu]![Status]))

)
ORDER BY [Forms]![Query Menu]![Sort By];
End Of SQL


I am In trouble, please help....
0
Comment
Question by:chulland
1 Comment
 
LVL 3

Accepted Solution

by:
guillems earned 70 total points
ID: 1969049
Think that the SQL statement is an string and you in your second SQL' statement say the next:

  'SELECT * FROM table WHERE <condition>
   ORDER BY [Forms]![Query Menu]![Sort By]'

and the statement will be
 
  'SELECT * FROM table WHERE <condition>
   ORDER BY table.field'

so the solution is to construct the Sentence.

  sSQL = 'SELECT ... '
  sSQL = sSQL & ' ORDER BY ' & forms![QUERY MENU]![SORT BY]
 
and this is the right. sentence.

I hope this help you.


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now