473,396 Members | 1,785 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,396 software developers and data experts.

Sort Order Combo box for report not working

53
Hi guys,

I have made a form with a combo box listing fields that a user can sort by. I have a code that works for this when i have 4 levels to sort by. It is the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOK_Click()
  2.  
  3. Dim strSQL As String, intCounter As Integer
  4. For intCounter = 1 to 4
  5.  If Me("cboSort" & intCounter) <> "" Then
  6.   strSQL = strSQL & Me("cboSort" & intCounter)
  7.  If Me("Chk" & intCounter) = True Then
  8.   strSQL = strSQL & " DESC"
  9.  End If
  10. strSQL = strSQL & ", "
  11. End If
  12. Next
  13.  If cboSupplier <> "" Then
  14.   DoCmd.OpenReport "rptProdPerSupp", acViewPreview
  15.   DoCmd.Maximize
  16.  If strSQL <> "" Then
  17.   strSQL = Left(strSQL, (Len(strSQL) - 2))
  18.   Reports![rptProdPerSupp].OrderBy = strSQL
  19.   Reports![rptProdPerSupp].OrderByOn = True
  20.  Else
  21.   Reports![rptProdPerSupp].OrderByOn = False
  22.  End If
  23.  Else
  24.   MsgBox "Please choose a supplier whose products you would like to see."
  25.  End If
  26.  
  27. End Sub
  28.  
This code works fine for multiple sorting levels. Now I have another form that has a single combo box in which you can choose a field to sort by. I tried translating the above code into one that uses just one combo box for sorting. Here is what I did:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOK_Click()
  2.  
  3. Dim strSQL As String
  4. If Me.cboSort1 <> "" Then
  5.  strSQL = strSQL & Me.cboSort1
  6.  If Me.Chk1 = True Then
  7.   strSQL = strSQL & " DESC"
  8.  End If
  9.  strSQL = strSQL & ", "
  10.  DoCmd.OpenReport "rptTopSuppliers", acViewPreview
  11.  DoCmd.Maximize
  12. If strSQL <> "" Then
  13.  strSQL = Left(strSQL, (Len(strSQL) - 2))
  14.  Reports![rptTopSuppliers].OrderBy = strSQL
  15.  Reports![rptTopSuppliers].OrderByOn = False
  16. Else
  17.  Reports![rptTopSuppliers].OrderByOn = True
  18. End If
  19. Else
  20.  MsgBox "Please choose a field to sort by.", vbOKOnly, "Missing Information"
  21. End If
  22. End Sub
  23.  
Needless to say, it does not sort. Can anyone pinpoint where I went wrong? The problem must lie in the first If statement in the code, since that is the only thing I changed.
Jul 26 '07 #1
3 3172
RZ15
53
can anyone help me with this?
Jul 27 '07 #2
RZ15
53
For the life of me I can't figure this out, can someone try taking a look at this please?
Jul 30 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Try this ...
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOK_Click()
  2. Dim strSQL As String
  3.  
  4.     If Me.cboSort1 <> "" Then
  5.         strSQL = Me.cboSort1
  6.         If Me.Chk1 = True Then
  7.             strSQL = strSQL & " DESC"
  8.         End If
  9.         DoCmd.OpenReport "rptTopSuppliers", acViewPreview
  10.         DoCmd.Maximize
  11.         If strSQL <> "" Then
  12.             Reports![rptTopSuppliers].OrderBy = strSQL
  13.             Reports![rptTopSuppliers].OrderByOn = True
  14.         Else
  15.             Reports![rptProdPerSupp].OrderByOn = False
  16.         End If
  17.     Else
  18.         MsgBox "Please choose a field to sort by.", vbOKOnly, "Missing Information"
  19.     End If
  20.  
  21. End Sub
  22.  
Aug 6 '07 #4

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

Similar topics

3
by: Charles | last post by:
I am trying to add the ability for a user to change the order in which the elements are listed in a dropdown list box. Before I added the ListID field the dropdown list box order was controlled...
11
by: James P. | last post by:
Hello, I have a report with the Priority field is used as sort order and grouping. The problem is the data in this Priority field if sorted in ascending order is: High, Low, and Medium. How...
5
by: Terri | last post by:
The following query will give me the top ten states with the most callers. SELECT TOP 10 Count(Callers.CallerID) AS CountOfCallerID, Callers.State FROM Callers GROUP BY Callers.State ORDER BY...
3
by: rquinnan | last post by:
Good Evening all, I would greatly appreciate any assistance on this Access 2003 quandary I'm in. And I do apologize if this has been answered somewhere else, I didn't see one that addressed my...
0
by: importantEmail | last post by:
hi i have pasted page_load, my bindgrid, sort and itemdatabound event. my sorting in not working properly...i tried a couple of ways but there is something i am missing. pls suggest me on this...
0
by: samir dsf | last post by:
hi i have pasted page_load, my bindgrid, sort and itemdatabound event. my sorting in not working properly...i tried a couple of ways but there is something i am missing. pls suggest me on this...
7
by: Arnold | last post by:
Greetings Gurus, In a mainform's header, I have a combobox named comboStudents. The rowsource for this combobox is: SELECT -999 As StudentID, "<Add New Student>" As FullName, "aaa" As...
9
by: thatguyNYC | last post by:
Hey there-- I have a report with a one-to-many relationship on it. The EmployeeName field is grouped (by primary key) and shown in its own header and the EmployeeHistories are displayed in the...
3
by: HowHow | last post by:
I need to sort the "DateOfBirth" by the day (dd) regarless of month (mm)and year (yyyy). I have a query called q_DC_Client, in criteria, I am using this code below: Like "*" & "/" & !! & "/" & "*"...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.