Reply To: Access: Find 2nd occurence of a string
by
regg
·
about 17 years, 2 months ago
In reply to Access: Find 2nd occurence of a string
Now, How did that happen: I only hit the Space bar:
So then you will need to again parse the results to create the directories.
I would first of all suggest changing the DB Table to have 3 different fields to store the 3 different segments – it’ll save alot of headaches latter.
Until then, I would just pull the complete contents of the field “as-is” and in a Sub Proceedure do the parsing as needed and create the folders.
Create a recordset and loop throught the records, passing the value of the field in question to the following proceedure:
Public Sub ParseFieldXYZ(ByVal FieldValue As Variant, Optional BasePath = “C:\MySongs”)
‘FieldValue uses a Variant in case the field contains a NULL
‘Sample: FieldValue = “Waylon Jennings – Honky Tonk Heroes – Omaha.mp3”
‘Change the optional parameter to the initial base path which you use. Under this path the Sub folders will be created
Dim oFSO As Object ‘Scripting.FileSystemObject
Dim ary() As String
Dim vElement As Variant
Dim sPath As String
Screen.MousePointer = vbHourglass
FieldValue = FieldValue & vbNullString ‘in case the field contains a NULL
‘Or
‘FieldValue = Format$(FieldValue)
If Len(FieldValue) Then
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
sPath = BasePath
If Not oFSO.FolderExists(sPath) Then oFSO.CreateFolder (sPath)
FieldValue = Mid$(FieldValue, 1, InStrRev(FieldValue, “-“) – 1)
ary = Split(FieldValue, “-“)
For Each vElement In ary
sPath = sPath & “\” & Trim$(vElement)
If Not oFSO.FolderExists(sPath) Then oFSO.CreateFolder (sPath)
Next vElement
Else
‘Error
End If
Set oFSO = Nothing
ExitHere:
Screen.MousePointer = vbDefault
Exit Sub
ErrHere:
MsgBox Err.Number & vbCr & Err.Description
Resume