Microsoft Access Substring function is mainly to extract the characters in the string. As we all know, the Substring function is not existed in Access, both in query or VBA Code. So how to extract the characters? Ms Access has several other functions that equivalent with the Substring function:
MS Access Substring LEFT Function
Left function is used for extract the characters from the string started from the first characters in left. The syntax for Left function: Left (string, [number of characters])
Parameters | Descriptions |
String | The word or text |
[number of characters] | the amount of characters to be taken |
Example: Left (“Bouncing off the wall”, 8)
Result: “Bouncing”
MS Access Substring RIGHT Function
Right function extracts the characters from a string started from the characters located in right.
The syntax for Right function: Right (string, [number of characters])
Example: Right (“Bouncing off the wall”, 8)
Result: “the wall”
MS Access Substring MID Function
Mid Function extract some characters from string data located in the middle of the string.
The syntax for Mid function: Mid (string, [start position], [number of characters])
Parameters | Descriptions |
[start position] | The position to start extracting the characters |
Example: Mid (“Bouncing off the wall”, 10, 3)
Result: “off”
MS Access Substring INSTR Function
Instr Function is quite different than 3 functions above. It has more parameters and different function, through the function is still one of the substring function usage. Instead of extracting the characters from a string, it will search the “substring” and returned the result as the position number of the substring.
The syntax for Instr Function: InStr ([start], string1, string2, [compare])
Parameters | Descriptions |
[start] | is the expression to set the starting position for each search |
string1 | the full text that going to be searched |
String2 | the string or “substring” that being to be sought |
[compare] | determine the type comparison for the string |
Example: InStr (3, “Bouncing off the wall”, “o”, 0)
Result: 10
To sum it all, look at this picture:
Example in the query:
In VBA code, the function will have not much changing. However, you will need to add the argument for the data type.
Related Access Database
- access substring
- microsoft access substring