In my code I have to use a wildcard "*" to search for a folder name that is simliar. This code works just fine in VBA (except for the Process.Start ...
line), but all it does now is open My Documents.
It is supposed to open a network folder.
The string pathStr
produces the final folder path, and that is correct
I have triple-checked the folder path (I copied what this code produces and pasted in Windows Explorer and the path checks out)
Why is my code only opening My Documents?
Private Sub OpenJobToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenJobToolStripMenuItem.Click
Dim jobnum As String = ListView1.SelectedItems(0).Text
'Define the master path to all job numbers
Dim masterpath As String = "\\ussatf02\Production\00A Job Folders\"
'Get the child folder path
Dim fullFolder As String = masterpath & jobnum.Substring(0, 5) & "xxx\"
'Get first 8 characters of job number
Dim jobFolder As String = jobnum.Substring(0, 8)
'Define the full path to the jobFolder
Dim xPath As String = fullFolder & jobFolder
'Check the full path with a wildcard to see if there is a folder named something simliar to what we have
Dim foundFolder As String = Dir(xPath & "*", vbDirectory)
'If the folder is not found (length < 2) then throw an error, else open the folder
If (foundFolder.Length < 2) Then
Dim msgRes As MsgBoxResult = MsgBox("The job folder for: " & jobnum & " could not be found.", vbCritical, "Error Finding Folder")
Else
'Define the final path of the folder
Dim pathStr As String = xPath & "\" & foundFolder
'Open the folder
System.Diagnostics.Process.Start("explorer.exe", pathStr)
End If
End Sub
Any help will be greatly appreciated!!
EDIT
I now substituted the line
Dim pathStr As String = xPath & "\" & foundFolder
For
Dim pathStr As String = System.IO.Path.GetDirectoryName(xPath & "\" & foundFolder)
And I still get the same result