Solved

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

Posted on 1998-02-23
1
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

733 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