Help with Split Function Array

J

JeffSnead

Let's say for example I have a filepath:

"N:/Private/LPC/RegTeam3/Washington/CAAR.xls"

With the Split function and using "/" and passing to an Array I know I
can get the LBound (N:) and Ubound (CAAR.xls), but how do I get the
other elements of the Array passed to variables that I can then put in
separate fields in a query. Also, the filepath is not always six
elements as the example above - it could be 6, 7, 8, 9... - wherever
the users decides to save the file to - it needs to be dynamic.

Thanks!
 
J

John Nurick

Hi Jeff,

I can't imagine needing to store the names of folders in a path in
separate fields, but my little SafeSplit() function may give you ideas:

Public Function SafeSplit(V As Variant, _
Delim As String, Item As Long) As Variant

On Error Resume Next 'to return Null if Item is out of range
SafeSplit = Split(V, Delim)(Item)
End Function

?SafeSplit("N:/Private/LPC/RegTeam3/Washington/CAAR.xls", "/", 4)
Washington
?SafeSplit("N:/Private/LPC/RegTeam3/Washington/CAAR.xls", "/", 9)
Null

Remember that you'll need to add code to identify and handle UNC paths.
 

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