I have yet another issue. I am having to adjust the code to below to compensate for two wildcard situations. First wildcard situation is looking for everything before the SupplierCode since SupplierCode is the unique identifier for the folder.
The second wildcard situation is looking for Body No within a file name.
When I originally had the code set up, I was only using wildcards around the Body No and it worked perfectly. Folder names have now changed and I am having to compensate.
When I run the code I get a Runtime Error 52. Not sure how it is possible when I copied the filepath directly from the windows dialog box. And it stops on the strFile = line
The second wildcard situation is looking for Body No within a file name.
When I originally had the code set up, I was only using wildcards around the Body No and it worked perfectly. Folder names have now changed and I am having to compensate.
When I run the code I get a Runtime Error 52. Not sure how it is possible when I copied the filepath directly from the windows dialog box. And it stops on the strFile = line
Code:
Dim sMyPath As FileDialog
Dim sPath As Variant
Dim strFolderPath As String
Dim strMessage2, strTitle2 As String
Dim fname As String
Dim strFile As String
Dim Response As String
Dim strBodyNo As String
Dim InputYear As String
Dim strSupCode As String
strSupCode = Me.SupplierCode
strBodyNo = Me.BodyNo
strMessage2 = "Would you like to open the file?"
strTitle2 = "Open Three Panel"
Set sMyPath = Application.FileDialog(msoFileDialogOpen)
strFolderPath = "R:\0.2.2 Procurement Dept - Shared\3.0 Groups\SQD\Suppliers\" & "*" & strSupCode & "\2015\FTTQ\"
Debug.Print "Looking for: " & strFolderPath & "*" & strBodyNo & "*"
strFile = Dir(strFolderPath & "*" & strBodyNo & "*")
'Debug.Print strFile
If (strFile <> "") Then
MsgBox strFolderPath
Response = MsgBox(strMessage2, vbYesNo, strTitle2)
If Response = vbYes Then
Application.FollowHyperlink strFile
End If
Else
MsgBox "No file found", , "No File"
End If