totn Access Functions

MS Access: Split Function

This MSAccess tutorial explains how to use the Access Split function with syntax and examples.

Description

The Microsoft Access Split function will split a string into substrings based on a delimiter. The result is returned as an array of substrings.

Syntax

The syntax for the Split function in MS Access is:

Split ( expression [,delimiter] [,limit] [,compare] )

Parameters or Arguments

expression
The string to split into substrings based on a delimiter.
delimiter
Optional. The delimiter used to split expression into substrings. If not specified, the delimiter will default to a space character.
limit
Optional. The maximum number of substrings split from expression. If not specified, the limit will default to -1 which will split out all substrings.
compare

Optional. This is the type of comparison to perform when parsing the substrings and can be one of the following:

VBA Constant Value Explanation
CompareMethod.Binary 0 Binary comparison
CompareMethod.Text 1 Textual comparison

Applies To

The Split function can be used in the following versions of Microsoft Access:

  • Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000

Example

Let's look at examples of how to use the Split function in MS Access:

Split ("one two three")
Result: {"one", "two", "three"}

Split ("one:two:three", ":")
Result: {"one", "two", "three"}

Split ("172.1.0.16", ".")
Result: {"172", "1", "0", "16"}

Split ("172.1.0.16", ".", 1)
Result: {"172.1.0.16"}

Split ("172.1.0.16", ".", 2)
Result: {"172", "1.0.16"}

Split ("172.1.0.16", ".", 3)
Result: {"172", "1", "0.16"}

Split ("172.1.0.16", ".", 4)
Result: {"172", "1", "0", "16"}

Example in VBA Code

The Split function can be used in VBA code in Microsoft Access.

For example:

Dim LString As String
Dim LArray() As String

LString = "Tech on the Net"
LArray = Split(LString)

MsgBox LArray(0)
MsgBox LArray(1)
MsgBox LArray(2)
MsgBox LArray(3)

In this example, the variable called LArray would now contain the array {"Tech", "on", "the", "Net"}. The four MsgBox statements would display the value stored in each element of the array.