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: -
Private Sub cmdOK_Click()
-
-
Dim strSQL As String, intCounter As Integer
-
For intCounter = 1 to 4
-
If Me("cboSort" & intCounter) <> "" Then
-
strSQL = strSQL & Me("cboSort" & intCounter)
-
If Me("Chk" & intCounter) = True Then
-
strSQL = strSQL & " DESC"
-
End If
-
strSQL = strSQL & ", "
-
End If
-
Next
-
If cboSupplier <> "" Then
-
DoCmd.OpenReport "rptProdPerSupp", acViewPreview
-
DoCmd.Maximize
-
If strSQL <> "" Then
-
strSQL = Left(strSQL, (Len(strSQL) - 2))
-
Reports![rptProdPerSupp].OrderBy = strSQL
-
Reports![rptProdPerSupp].OrderByOn = True
-
Else
-
Reports![rptProdPerSupp].OrderByOn = False
-
End If
-
Else
-
MsgBox "Please choose a supplier whose products you would like to see."
-
End If
-
-
End Sub
-
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: -
Private Sub cmdOK_Click()
-
-
Dim strSQL As String
-
If Me.cboSort1 <> "" Then
-
strSQL = strSQL & Me.cboSort1
-
If Me.Chk1 = True Then
-
strSQL = strSQL & " DESC"
-
End If
-
strSQL = strSQL & ", "
-
DoCmd.OpenReport "rptTopSuppliers", acViewPreview
-
DoCmd.Maximize
-
If strSQL <> "" Then
-
strSQL = Left(strSQL, (Len(strSQL) - 2))
-
Reports![rptTopSuppliers].OrderBy = strSQL
-
Reports![rptTopSuppliers].OrderByOn = False
-
Else
-
Reports![rptTopSuppliers].OrderByOn = True
-
End If
-
Else
-
MsgBox "Please choose a field to sort by.", vbOKOnly, "Missing Information"
-
End If
-
End Sub
-
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.
3 3172
can anyone help me with this?
For the life of me I can't figure this out, can someone try taking a look at this please?
Try this ... -
Private Sub cmdOK_Click()
-
Dim strSQL As String
-
-
If Me.cboSort1 <> "" Then
-
strSQL = Me.cboSort1
-
If Me.Chk1 = True Then
-
strSQL = strSQL & " DESC"
-
End If
-
DoCmd.OpenReport "rptTopSuppliers", acViewPreview
-
DoCmd.Maximize
-
If strSQL <> "" Then
-
Reports![rptTopSuppliers].OrderBy = strSQL
-
Reports![rptTopSuppliers].OrderByOn = True
-
Else
-
Reports![rptProdPerSupp].OrderByOn = False
-
End If
-
Else
-
MsgBox "Please choose a field to sort by.", vbOKOnly, "Missing Information"
-
End If
-
-
End Sub
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 "*" & "/" & !! & "/" & "*"...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |