Reverse Sorting

T

Tatakau

I have a button on [Form1] that opens up [Form2] when clicked, sending an ID
number as an argument. In the VB Code for [Form2], I have it set to sort all
records by ID number first, followed by a secondary sort by Tour numbers.
Here is the code:

Dim strSQL As String
If Not IsNull(Me.OpenArgs) Then
strSQL = "SELECT * FROM [QueryMVCScheduleandCommunications] ORDER BY
" & _
"IIF([LeadNumber] = " & Me.OpenArgs & ", 1, 2), TourNumber"
Me.RecordSource = strSQL
End If

However, I wish to reverse sort by TourNumber. Thus, if someone (identified
by an ID (Lead) number) has multiple tours, the larger TourNumber (and thus,
the most recent tour) will come up first.

Thank you!

Nick

Example:

Current Desired

ID TourNum ID TourNum
1 34 1 46
1 46 1 34
2 23 2 23
3 35 3 35
4 63 4 67
4 67 4 63
 
B

Brian

Add "DESC" after ""Tour Number" to indicate descending.

Dim strSQL As String
If Not IsNull(Me.OpenArgs) Then
strSQL = "SELECT * FROM [QueryMVCScheduleandCommunications] ORDER
BY " & "IIF([LeadNumber] = " & Me.OpenArgs & ", 1, 2), TourNumber DESC"
Me.RecordSource = strSQL
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top