Home  Fees/Services  Access 2010 Template  Access Tutorial  Access Download  Articles  Search  Contact  Privacy  Links

Sort Recordset Quickly
Quick Sort Access






Visual Basic Tutorials:
Access-Google Earth
Age Calculation
Change To Proper Case
Email via Gmail #1
Send Gmail Email #2
Inactivity Logout Code
Outlook Email
Read Email Access
Email Attachment
Send Outlook Email
Running Sum
Concatenate Records
Stock Quotes
CreateQueryDef
Find Database Path
Detail-Master Update
Data Field Validation
Field Value New-Old
FindFirst
Access Version
Global Variable Parameter
Global Variables
Active Labels
Files List Box
Mail Merge
Quick Sort
Recordset Filters
Reference Form Field
Select Case
Access Transactions


Visual Basic Function Examples


Quick Sort VBA

Access VBA Recursive Quick Sort Program:  At times you may need to sort a list of values programmatically. One of the most efficient and easiest sorts is the recursive quick sort. Recursive means that the routine calls itself.
The concept used in the quick sort is as follows:



Our programming team has 15 members containing a wide variety of technical database knowledge and programming experience. We are kind of like Allstate Insurance - 'we have seen it before'.

Do you and your clients need access to data on the Internet? We can create a secure system to match your requirements perfectly.


  1. Choose the middle value of the list.

  2. Starting at the bottom of the list move up the list, toward the middle, until you find the first value that is not in sort order in relation to the middle value.

  3. Starting at the top of the list move down the list, toward the middle, until you find the first value that is not in sort order in relation to the middle value.

  4. Now switch the two values that were found out of sort order.

  5. Repeat steps 2 through five until you get to the middle of the list.

  6. Call the sort routine on the top half of the list.

  7. Call the sort routine on the bottom half of the list.

What happens is that each pass through the routine does a small amount of sorting then cuts the size of the list in half and sends the 2 new halves to be sorted. This continues until each part of the list is perfectly sorted. The result is that the overall whole is sorted.

Private Sub QuickSort(strArray() As String, intBottom As Integer, intTop As Integer)
Dim strPivot As String, strTemp As String
Dim intBottomTemp As Integer, intTopTemp As Integer

intBottomTemp = intBottom
intTopTemp = intTop

strPivot = strArray((intBottom + intTop) \ 2)

While (intBottomTemp <= intTopTemp)

'  comparison of the values is a descending sort
While (strArray(intBottomTemp) < strPivot And intBottomTemp < intTop)
    intBottomTemp = intBottomTemp + 1
Wend

While (strPivot < strArray(intTopTemp) And intTopTemp > intBottom)
    intTopTemp = intTopTemp - 1
Wend
If intBottomTemp < intTopTemp Then
    strTemp = strArray(intBottomTemp)
    strArray(intBottomTemp) = strArray(intTopTemp)
    strArray(intTopTemp) = strTemp
End If

If intBottomTemp <= intTopTemp Then
    intBottomTemp = intBottomTemp + 1
    intTopTemp = intTopTemp - 1
End If

Wend

'the function calls itself until everything is in good order
If (intBottom < intTopTemp) Then QuickSort strArray, intBottom, intTopTemp
If (intBottomTemp < intTop) Then QuickSort strArray, intBottomTemp, intTop

End Sub

Quick Sort contributed by Janet Loch










Blue Claw Database Design Downloadable Tutorial:
Programming Crosstab Query Example  








A Blue Claw Software Design Template:

Preventive Maintenance (PM) Access Template
 










A Blue Claw Database Design Article:

Software Risk Assessment
 

Microsoft Office:
MS Access 2000 Through 2016 and Office 365 & Sharepoint


Contact Information

Copyright 2000-2017 Blue Claw Database Design

Microsoft Access 2007, 2010, 2013 & 2016