473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Sorting a select statement within VBA

52
Can someone help me enter a sort statement into the below SQL statement? For the life of me I can not get it to work and I have tried everything I can think of. I just need this stupid thing to sort on the Element_Name but I can not find the proper syntax to get it to work.

Any help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Project_Name_AfterUpdate()
  2. Dim strSQL As String
  3. Dim intSQL As Integer
  4.  
  5.     Me!Element_Name.RowSource = ""
  6.  
  7.     strSQL = IIf(Me!Project_Name > "", _
  8.                  "SELECT [Element_Name] " & _
  9.                  "FROM [Elements] " & _
  10.                  "WHERE ([Project_Name]='" & Me!Project_Name & "')", _
  11.                  "")
  12.     With Me!Element_Name
  13.         .RowSource = strSQL
  14.         .Enabled = (.ListCount > 0)
  15.     End With
  16.  
  17. '    Me!Element_Name.RowSource = strSQL
  18.  
  19. End Sub
Thanks
Birky
Feb 10 '07 #1
4 2736
hariharanmca
1,977 1GB
Can someone help me enter a sort statement into the below SQL statement? For the life of me I can not get it to work and I have tried everything I can think of. I just need this stupid thing to sort on the Element_Name but I can not find the proper syntax to get it to work.

Any help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Project_Name_AfterUpdate()
  2. Dim strSQL As String
  3. Dim intSQL As Integer
  4.  
  5.     Me!Element_Name.RowSource = ""
  6.  
  7.     strSQL = IIf(Me!Project_Name > "", _
  8.                  "SELECT [Element_Name] " & _
  9.                  "FROM [Elements] " & _
  10.                  "WHERE ([Project_Name]='" & Me!Project_Name & "')", _
  11.                  "")
  12.     With Me!Element_Name
  13.         .RowSource = strSQL
  14.         .Enabled = (.ListCount > 0)
  15.     End With
  16.  
  17. '    Me!Element_Name.RowSource = strSQL
  18.  
  19. End Sub
Thanks
Birky
Use 'Order By Element_Name' after where Clause
Feb 10 '07 #2
hariharanmca
1,977 1GB
Can someone help me enter a sort statement into the below SQL statement? For the life of me I can not get it to work and I have tried everything I can think of. I just need this stupid thing to sort on the Element_Name but I can not find the proper syntax to get it to work.

Any help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Project_Name_AfterUpdate()
  2. Dim strSQL As String
  3. Dim intSQL As Integer
  4.  
  5.     Me!Element_Name.RowSource = ""
  6.  
  7.     strSQL = IIf(Me!Project_Name > "", _
  8.                  "SELECT [Element_Name] " & _
  9.                  "FROM [Elements] " & _
  10.                  "WHERE ([Project_Name]='" & Me!Project_Name & "')", _
  11.                  "")
  12.     With Me!Element_Name
  13.         .RowSource = strSQL
  14.         .Enabled = (.ListCount > 0)
  15.     End With
  16.  
  17. '    Me!Element_Name.RowSource = strSQL
  18.  
  19. End Sub
Thanks
Birky
Order By Element_Name Asc
Order By Element_Name Desc
Feb 10 '07 #3
Birky
52
That’s what I thought, I had just omitted the “Acs” part. Once I added this to my order by statement everything worked.

Thanks for the help..
Birky
Feb 11 '07 #4
NeoPa
32,556 Expert Mod 16PB
The ASC or DESC qualifiers sort Ascending or Descending, but it always defaults to ASC if no qualifier is specified.
You probably had some small error in your SQL before. Frustratingly you had the correct understanding but not the experience and confidence to know that.
It's sorted now, that's the main thing :)
Feb 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Tim | last post by:
I've been working on this for over a week now, and just can't get this figured out. Hoping one of you gurus can help me out here. I have an xml data island that I'm representing on an htm page as...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
2
by: drud via AccessMonster.com | last post by:
Is anybody know what algorithms of sorting are realized in Access? I know that this theme is strange but i have to find any information about it... All that I found is "Many of the sort algorithms...
2
by: Clinton Pierce | last post by:
I've filled a DataTable with columns that have custom type (a class that I'm using to keep track of other things, not just a value). When the .Select method goes to sort this column, how do I let...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
4
by: Roy | last post by:
Greetings, I've been avoiding it for so long, but like an evil wraith it always returns to haunt me. The bane of my existence, it is... bidirectional sorting!!! Checked out previous posts and...
2
by: Chris Kratz | last post by:
We are having a weird problem that we ran into recently. If I use the following statements to create a test table and then run the select statement at the end, we get a very strange sort order. ...
8
by: sara | last post by:
Hi - I have looked at all posts and tried both Allen Browne's Report Sorting at run Time ( Select Case Forms!frmChooseSort!grpSort Case 1 'Name Me.GroupLevel(0).ControlSource = "LastName"...
10
by: MattC | last post by:
Hi, I wanted to take advantage of the Row_Number feature of SQL 2005 to to DB side paging. However, currently I perform my sorting on the front end. If I perform a sort and then ask for page...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.