Home Privacy Policy Feedback Link to us Site Map Forums

Access: Mid Function


In Access, the Mid function extracts a substring from a string (starting at any position).

The syntax for the Mid function is:

Mid ( text, start_position, number_of_characters )

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.


For example:

Mid ("Tech on the Net", 1, 4) would return "Tech"
Mid ("Alphabet", 5, 2) would return "ab"
Mid ("Alphabet", 5) would return "abet"

VBA Code

The Mid function can be used in VBA code. 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.


SQL/Queries

You can also use the Mid function in a query.