> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Sorting Arrays of Strings in Access with WizHook
- URL: https://nolongerset.com/sortstringarray/
- Published: 2022-11-03T02:56:40.000Z
- Updated: 2026-05-08T12:53:47.000Z
- Description: No need to write your own array-sorting code from scratch. Use the SortStringArray method of Access's hidden WizHook object instead!
- Author: Mike Wolfe
- Tags: WizHook, Code Library, #WizHook, #Import 2026-05-20 02:59

One of the more interesting methods of the undocumented [WizHook object](https://nolongerset.com/wizhook/) in Microsoft Access is `WizHook.SortStringArray`.

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2022/11/image-2.png)

As the name suggests, the `WizHook.SortStringArray` routine sorts an array of strings *in place*. By "in place," we mean that the original array variable gets overwritten.

## Basic Usage

The SortStringArray routine is one of the few methods of the WizHook object that do not require setting the [magic key](https://nolongerset.com/wiz-wizhook-helper/) before use.

In fact, you don't need to do anything special to use the function at all, though there are a few things to be aware of:

- You won't see IntelliSense for this method unless you right-click in the Object Browser and check the box to **\[√\] Show Hidden Members**
- If you leave **\[ \] Show Hidden members** *unchecked*, the code will still work (just, you know, no IntelliSense)
- The array being sorted must be declared using the array syntax and explicitly set to the String type; e.g.,  
**GOOD**: `Dim Vals() As String`  
**BAD:** `Dim Vals() As Variant`  
**BAD:** `Dim Vals As Variant`
- While you *can* sort numbers stored as strings using this function, the stringified numbers get sorted in "alphabetical" order–not numerical order
- The `WizHook` object is a member of the Access library–not the standard VBA library–so this won't work in other Office applications1

1\. *Unless you include a reference to Access and Access is present on the end user's machine*

Once you have a populated array, you simply pass it to the `WizHook.SortStringArray` method to sort it alphabetically:

```vba
WizHook.SortStringArray MyArray
```

## Usage Samples

I'll be using the `PrintArray` function to output array values to the immediate window in my samples below:

```vba
Sub PrintArray(Values As Variant)
    Dim i As Long
    For i = LBound(Values) To UBound(Values)
        'The trailing comma will separate values with tabs
        '	without adding line breaks between Debug.Print calls
        Debug.Print Values(i),   
    Next i
    Debug.Print   'Add line break
End Sub
```

### Basic Sample

The following sample illustrates how the function works using an explicitly populated, strongly-typed string array:

```vba
Sub Test1()
    Dim MyArray(0 To 3) As String
    MyArray(0) = "Happy"
    MyArray(1) = "30th"
    MyArray(2) = "Birthday"
    MyArray(3) = "Access"
    
    PrintArray MyArray
    WizHook.SortStringArray MyArray
    PrintArray MyArray
End Sub
```

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2022/11/image-4.png)

### Generating a String Array with Split()

This example uses the Split() function to quickly create a string array suitable for sorting with WizHook. Note the following:

- The array is not explicitly dimensioned (*i.e., the parentheses are empty in the declaration line*)
- The array is explicitly typed (*i.e., it is declared `As String`)*
- The variable must be an array and not a `Variant`; a Variant would be compatible with the Split() function but is not compatible with `WizHook.SortStringArray`

```vba
Sub Test2()
    Dim MyArray() As String
    MyArray = Split("WizHook is the coolest")
    
    PrintArray MyArray
    WizHook.SortStringArray MyArray
    PrintArray MyArray
End Sub
```

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2022/11/image-6.png)

### Sorting Values Passed via ParamArray

This routine shows how to accept a variable number of parameters and still sort them using the `SortStringArray` method. It also doubles as a handy way to run additional tests to better understand the sort ordering and capabilities of the `SortStringArray` method:

```vba
Sub TestWizHookSort(ParamArray Values() As Variant)
    'The array must be declared `As String` because
    '   WizHook.SortStringArray only works with arrays of *Strings*
    Dim Temp() As String
    
    'Redimension the temp array to fit the number of parameters passed
    ReDim Temp(LBound(Values) To UBound(Values))
    
    'Populate the temporary array
    Dim i As Long
    For i = LBound(Values) To UBound(Values)
        Temp(i) = Values(i)
    Next i
    
    'Print the unsorted array
    Debug.Print
    Debug.Print "Unsorted:",
    PrintArray Temp
    
    'Sort the array
    WizHook.SortStringArray Temp
    
    'Print the sorted array
    Debug.Print "Sorted:",
    PrintArray Temp
    Debug.Print
End Sub
```

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2022/11/image-7.png)

### Referenced articles

[WizHook: A Hidden Access Object With Intriguing PotentialFont-aware AutoFit of text and combo boxes, auto-bracketing of illegal field names, sorting an array of strings...the possibilities are finite!![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2022/10/gandalf-4510395_1920.jpg)](https://nolongerset.com/wizhook/)

*Image by [Angela](https://pixabay.com/users/meisjedevos-4648054/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=2183684) from [Pixabay](https://pixabay.com//?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=2183684)*