Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1998-02-23
1
Medium Priority
?
209 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 140 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

597 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