Application.FollowHyperlink Problem

PatAccess

Registered User.
Local time
Today, 08:10
Joined
May 24, 2017
Messages
284
Hello Guys,

I am trying to get my code to follow a file path if it exists or just pop-up a msgbox if it doesn't. However now it is just basically showing me the pop up. What am I doing wrong? Here is my code:
Code:
Private Sub cmdGotoFolder_Click()
Dim strFile As String
Dim strFilePath As String
strFile = Me.cboFolders.Column(1)
strFilePath = "C:\" & strFile
If Dir(strFilePath) <> "" Then
Application.FollowHyperlink strFilePath
Else
MsgBox "No folder was found!" & vbNewLine & "Please create one and try again" & vbNewLine & "Thank you.", vbCritical, "No Folder found!"
End If
End Sub

Thank you
 
It suggests that the variable for the path is always "". Possibly as a result of you using the wrong combo column, as the column reference is 0 based.

Step through this code and mouse over the strFilePath variable after that line has been processed or debug.print the variable to the immediate window and check it. That is an approach you should adopt for these situations.
 
To help isolate the issue, I recommend you use some debug.print statements to show values.

Code:
Private Sub cmdGotoFolder_Click()
Dim strFile As String
Dim strFilePath As String
strFile = Me.cboFolders.Column(1)
[COLOR="Blue"]debug.print "strfile  " & strfile & vbcrlf _ 
 & "   Me.cboFolders.Column(1)  " & Me.cboFolders.Column(1)[/COLOR]
strFilePath = "C:\" & strFile
If Dir(strFilePath) <> "" Then
  Application.FollowHyperlink strFilePath
Else
  MsgBox "No folder was found!" & vbNewLine & "Please create one and try again" & vbNewLine & "Thank you.", vbCritical, "No Folder found!"
End If
End Sub

Good luck.
 
It suggests that the variable for the path is always "". Possibly as a result of you using the wrong combo column, as the column reference is 0 based.

Step through this code and mouse over the strFilePath variable after that line has been processed or debug.print the variable to the immediate window and check it. That is an approach you should adopt for these situations.

Hi. Thank you for the response. Column(0) is just the FolderID and Column(1) is the folderName. and I just step through the code and it is correct but it is still showing me the MsgBox.

When I use If Not IsNull(strFilePath) Then it shows the existing folder but gives me an error for the non-existing ones
 
To help isolate the issue, I recommend you use some debug.print statements to show values.

Code:
Private Sub cmdGotoFolder_Click()
Dim strFile As String
Dim strFilePath As String
strFile = Me.cboFolders.Column(1)
[COLOR="Blue"]debug.print "strfile  " & strfile & vbcrlf _ 
 & "   Me.cboFolders.Column(1)  " & Me.cboFolders.Column(1)[/COLOR]
strFilePath = "C:\" & strFile
If Dir(strFilePath) <> "" Then
  Application.FollowHyperlink strFilePath
Else
  MsgBox "No folder was found!" & vbNewLine & "Please create one and try again" & vbNewLine & "Thank you.", vbCritical, "No Folder found!"
End If
End Sub

Good luck.

Hi. Thank you for responding. I added the Debug.Print and it actually prints the correct FolderName. I don't know how to check that this Directory exist which I believe is my problem
 
Hi. Thank you for the response. Column(0) is just the FolderID and Column(1) is the folderName. and I just step through the code and it is correct but it is still showing me the MsgBox.

When I use If Not IsNull(strFilePath) Then it shows the existing folder but gives me an error for the non-existing ones
Hi. To check if a folder path exist, you do want to use the Dir() function. Can you tell us what you get with the following?


Debug.Print strFilePath
 
Hi. To check if a folder path exist, you do want to use the Dir() function. Can you tell us what you get with the following?


Debug.Print strFilePath

It gives me the correct file path (C:\Tunnel.....) BUT it goes straight to the MsgBox even though the folder exist.
 
It gives me the correct file path (C:\Tunnel.....) BUT it goes straight to the MsgBox even though the folder exist.
So, in the Immediate Window, try to copy the result of the Debug.Print strFilePath and paste it within a Dir() function call. For example:


?Dir("copyandpastehere")


What do you get?
 
So, in the Immediate Window, try to copy the result of the Debug.Print strFilePath and paste it within a Dir() function call. For example:


?Dir("copyandpastehere")


What do you get?

It prints that filepath or that filepath with another folder path
 
It prints that filepath or that filepath with another folder path
Thanks. That tells me the Dir(strFilePath) line in your is working fine. The next step I would suggest is check all the data in your combobox. If it's based on a query, you can post the SQL statement here, so we can take a look.
 
Thanks. That tells me the Dir(strFilePath) line in your is working fine. The next step I would suggest is check all the data in your combobox. If it's based on a query, you can post the SQL statement here, so we can take a look.

Ok I am going to check everything and I read on something and just used a FolderExist(). It is working so far so here is the working code but I have to make sure that this will truly work :confused:
Code:
Function FolderExists(strFilePath As String) As Boolean
On Error Resume Next
FolderExists = ((GetAttr(strFilePath) And vbDirectory) = vbDirectory)
End Function
Private Sub cmdGotoFolder_Click()
Dim strFile As String
Dim strFilePath As String
strFile = Me.cboFolders.Column(1)
'Debug.Print "strfile  " & strFile & vbCrLf _
 '& "   Me.cboFolders.Column(1)  " & Me.cboFolders.Column(1)
strFilePath = "C:\" & strFile
'Debug.Print strFilePath
If FolderExists(strFilePath) = True Then
Application.FollowHyperlink strFilePath
Else
MsgBox "No folder was found!" & vbNewLine & "Please create one and try again" & vbNewLine & "Thank you.", vbCritical, "No Folder found!"
End If

End Sub
 
Hi. Okay. Good luck and let us know how it goes.
 
Did you consider navigating to a folder by using the folder picker (msoFileDialogFolderPicker)? That way any folder path can be returned to your code - no worries about whether or not it exists, plus gives you the option to choose any folder you have visibility of.
 

Users who are viewing this thread

Back
Top Bottom