Splitting a field into multiple fields

G

Guest

I have a file that has multiple fields within one. Each value is seperated by
a semi colon. Can anyone help me with the split function?
 
G

Guest

Ashley,

I have a Parse ( ) function that uses the Split function but allows me to
select a specific element (postion) of the Expression being parsed, if I so
desire.

If the format of your field is such that it always has the same number of
values (lets say 3) you could do something like:

SELECT [yourField], _
Parse([yourField],";",1) as Part1, _
Parse([yourField],";",2) as Part2, _
Parse([yourField], ";",3) as Part3
From [yourTable]

You could then use this to update fields in another table, or just
permanently parse the field into other fields in the same table.

Public Function Parse(Expression As String, _
Optional Delimiter As String = " ", _
Optional Element As Variant = Null) As Variant

'This function will return an array(like Split) if no element is passed
'If the element requested is more than the number of segments when
'split, the function returns an empty string ""
Dim A As Variant

A = Split(Expression, Delimiter)

If IsNull(Element) Then
Parse = A
ElseIf Element <= UBound(A) + 1 Then
Parse = A(Element - 1)
Else
Parse = ""
End If

End Function

HTH
Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top