AndyCabbages
Registered User.
- Local time
- Today, 07:39
- Joined
- Feb 15, 2010
- Messages
- 74
I am having difficulty getting my sort function to work on a report. Below is the code being used in the report:
Private Sub Report_Open(Cancel As Integer)
mainsql = "SELECT Quote_Number, Company_Name, Date, Contact_Name, Contact_Number, PreparedBy FROM Quotations "
addSQL = ""
If Forms![Main Reports]!Sorting1 <> "(Not Sorted)" Then
addSQL = "ORDER BY " & Forms![Main Reports]!Sorting1
If Forms![Main Reports]!Choice1 = 1 Then
addSQL = addSQL & " DESC"
End If
If Forms![Main Reports]!Sorting2 <> "(Not Sorted)" Then
addSQL = addSQL & ", " & Forms![Main Reports]!Sorting2
If Forms![Main Reports]!Choice2 = 1 Then
addSQL = addSQL & " DESC"
End If
If Forms![Main Reports]!Sorting3 <> "(Not Sorted)" Then
addSQL = addSQL & "," & Forms![Main Reports]!Sorting3
If Forms![Main Reports]!Choice3 = 1 Then
addSQL = addSQL & " DESC"
End If
End If
End If
End If
mainsql = mainsql + addSQL
RecordSource = mainsql
End Sub
The sorting is supposed to be controlled by 3 sort boxs on the form 'Main Reports' form which has a drop down menu to select which field is sorted by (Sorting1, sorting2, sorting3). Within these boxes there is a toggle switch for assending/decending (Choice1, choice2,choice3).
Currently whenever any of the sort boxes are given a value to sort by it does not work and no sorting is applied to the report. I cant seem to figure out why its not working
Private Sub Report_Open(Cancel As Integer)
mainsql = "SELECT Quote_Number, Company_Name, Date, Contact_Name, Contact_Number, PreparedBy FROM Quotations "
addSQL = ""
If Forms![Main Reports]!Sorting1 <> "(Not Sorted)" Then
addSQL = "ORDER BY " & Forms![Main Reports]!Sorting1
If Forms![Main Reports]!Choice1 = 1 Then
addSQL = addSQL & " DESC"
End If
If Forms![Main Reports]!Sorting2 <> "(Not Sorted)" Then
addSQL = addSQL & ", " & Forms![Main Reports]!Sorting2
If Forms![Main Reports]!Choice2 = 1 Then
addSQL = addSQL & " DESC"
End If
If Forms![Main Reports]!Sorting3 <> "(Not Sorted)" Then
addSQL = addSQL & "," & Forms![Main Reports]!Sorting3
If Forms![Main Reports]!Choice3 = 1 Then
addSQL = addSQL & " DESC"
End If
End If
End If
End If
mainsql = mainsql + addSQL
RecordSource = mainsql
End Sub
The sorting is supposed to be controlled by 3 sort boxs on the form 'Main Reports' form which has a drop down menu to select which field is sorted by (Sorting1, sorting2, sorting3). Within these boxes there is a toggle switch for assending/decending (Choice1, choice2,choice3).
Currently whenever any of the sort boxes are given a value to sort by it does not work and no sorting is applied to the report. I cant seem to figure out why its not working