Hi,
I have a field in a table from which I want to split the value in multiple strings.
Delimiter is ">".
Example input: "[string1] > [string2] > [string3] > [string4]"
wanted output: variable1 has value [string1], variable2 has value [string2], etc...
In this forum, I found this public function: (thanks to boblarson)
Boblarson then elaborated you have to use this syntax in the query:
MyField1:SplitFile(1,[YourUnSplitFieldName],",")
MyField2:SplitFile(2,[YourUnSplitFieldName],",")
etc ...
I've copied this code to a module, named the module "mod1".
Then in a query, I create a new column with following fieldname:
test1: SplitFile(1, [fieldA], ">")
Everytime I want to validatie this line, Access says:
"The expression you entered contains invalid syntax.
You may have entered an operand without an operator."
I tried it with following line, just to test:
test1: SplitFile(1, "test1,test2", ",")
But Access keeps firing the same error message box.
Also using semicolon instead of a comma doesn't help.
Does anyone know what I'm doing wrong here?
(using MS Access 2016)
I have a field in a table from which I want to split the value in multiple strings.
Delimiter is ">".
Example input: "[string1] > [string2] > [string3] > [string4]"
wanted output: variable1 has value [string1], variable2 has value [string2], etc...
In this forum, I found this public function: (thanks to boblarson)
Code:
Option Compare Database
Public Function SplitFile(intField As Integer, strValue As String, strDelimiter As String) As String
Dim varSplit As Variant
varSplit = Split(strValue, strDelimiter, , vbTextCompare)
SplitFile = varSplit(intField)
End Function
MyField1:SplitFile(1,[YourUnSplitFieldName],",")
MyField2:SplitFile(2,[YourUnSplitFieldName],",")
etc ...
I've copied this code to a module, named the module "mod1".
Then in a query, I create a new column with following fieldname:
test1: SplitFile(1, [fieldA], ">")
Everytime I want to validatie this line, Access says:
"The expression you entered contains invalid syntax.
You may have entered an operand without an operator."
I tried it with following line, just to test:
test1: SplitFile(1, "test1,test2", ",")
But Access keeps firing the same error message box.
Also using semicolon instead of a comma doesn't help.
Does anyone know what I'm doing wrong here?
(using MS Access 2016)
Last edited: