Share this page:

MS Access: Mid Function

Learn how to use the Access Mid function with syntax and examples.

Description

The Microsoft Access Mid function extracts a substring from a string (starting at any position).

Syntax

The syntax for the Microsoft Access Mid function is:

Mid ( text, start_position, number_of_characters )

Parameters or Arguments

Text is the string that you wish to extract from.

Start_position indicates the position in the string that you will begin extracting from. The first position in the string is 1.

Number_of_characters indicates the number of characters that you wish to extract. If you omit this parameter, the Mid function will return all characters after the start_position.

Applies To

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

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

Example

Mid ("Tech on the Net", 1, 4)
Result: "Tech"

Mid ("Alphabet", 5, 2)
Result: "ab"

Mid ("Alphabet", 5)
Result: "abet"

Example (in VBA Code)

The Mid function can be used in VBA code in Microsoft Access. For example:

Dim LResult As String

LResult = Mid ("Alphabet", 5, 2)

The variable LResult would now contain the value of "ab".

If you omitted the number_of_characters parameter in the above example:

Dim LResult As String

LResult = Mid ("Alphabet", 5)

The variable LResult would now contain the value of "abet", since omitting the final parameter will return all characters after the start_position.

Example (in SQL/Queries)

You can also use the Mid function in a query in Microsoft Access.

Microsoft Access