Solved Run-Time Error '490'

PatAccess

Registered User.
Local time
Today, 15:53
Joined
May 24, 2017
Messages
284
Hello all,
Here is my code:
Code:
Private Sub cmdFolderPath_Click()
Dim strMainPath As String
Dim strFolderPath As String
Dim strfolderName As String

strfolderName = Me.cboFolders.Column(1)
strMainPath = "..\Documents\RMF Photos\"
strFolderPath = strMainPath & strfolderName

If FolderExists(strFolderPath) = True Then
    Application.FollowHyperlink strFolderPath
Else
    MsgBox "No folder was found!" & vbNewLine & "Either check the spelling or create a folder." & vbNewLine & "Thank you!", vbCritical
End If

End Sub
when I click on the button, I first get the "Microsoft Access Security Notice" that this folder might be unsafe (it is not). Then I click yes to continue, I get Error 490 - Cannot open the specified file, but the line to debug actually shows that it is reading the file path so what is the problem?

Thank you for your help
 
How about trying to use the full/absolute path (including the drive letter)? Just a thought...
 
How about trying to use the full/absolute path (including the drive letter)? Just a thought...
Yes, but what if I want my code to read the drive no matter where that folder is moved?
 
Yes, but what if I want my code to read the drive no matter where that folder is moved?
I was just saying to "try it out." Did it work if you add the drive letter? If so, then I guess you'll need to always have it with the path. If that's the case, then check the drive letter for your program, and then add it to your path. If it didn't work, then you won't have to worry about "how" to figure out the drive letter. Just thinking out loud...
 
I was just saying to "try it out." Did it work if you add the drive letter? If so, then I guess you'll need to always have it with the path. If that's the case, then check the drive letter for your program, and then add it to your path. If it didn't work, then you won't have to worry about "how" to figure out the drive letter. Just thinking out loud...
Yes it works when I add the absolute path but not when I removed it and add ..\ and I thought there was a way to fix it for make the DB movable
 
I've always followed the "don't use mapped drive letters if possible" rule of thumb and prefer full UNC. Drive letters can change from user to user, but the full path will always be the full path. (unless, of course, someone deletes or moves the end folder ... but that's a risk no matter which method you use).
Anyway, so is the final strFolderPath really just the path to a folder? Or is it the path to a file? You have used both terms back and forth and it is hard to tell which is in play

EDIT, I see once I post this that it is working for you now.
 
I've always followed the "don't use mapped drive letters if possible" rule of thumb and prefer full UNC. Drive letters can change from user to user, but the full path will always be the full path. (unless, of course, someone deletes or moves the end folder ... but that's a risk no matter which method you use).
Anyway, so is the final strFolderPath really just the path to a folder? Or is it the path to a file? You have used both terms back and forth and it is hard to tell which is in play

EDIT, I see once I post this that it is working for you now.
It is the full path to the folder not a file
 
I'd like to add that, if your intention is to grab the location of the current user's My Documents or Documents folder, no matter where or who they are, I think that's legit and laudable. And there are ways to do that. In most companies I've worked at, it was as simple as getting the logged in user's username (Environ() or there is an API for it too), and then concatenating the appropriate path.
 
Yes it works when I add the absolute path but not when I removed it and add ..\ and I thought there was a way to fix it for make the DB movable
Okay, that tells me you cannot use relative path, so you'll need to use absolute path. But to make the DB "movable," you'll have to dynamically determine the drive letter at runtime (during code execution). Do you know how to do that? Basically, something like:

strFolderPath = GetDriveLetter() & strMainPath & strfolderName

You'll have to create a function to make GetDriveLetter() work. The above is just an example (idea).
 
Okay, that tells me you cannot use relative path, so you'll need to use absolute path. But to make the DB "movable," you'll have to dynamically determine the drive letter at runtime (during code execution). Do you know how to do that? Basically, something like:

strFolderPath = GetDriveLetter() & strMainPath & strfolderName
No I don't know how to do that. Can you give me some guidance, please?
Thank you for the help
 
No I don't know how to do that. Can you give me some guidance, please?
Thank you for the help
Sure. So, "..\" implies the "current" folder. How do we know what the current folder is? When you execute this code, in what context is it running. For example, can we assume the current folder is the same folder where the DB is stored?
 
Sure. So, "..\" implies the "current" folder. How do we know what the current folder is? When you execute this code, in what context is it running. For example, can we assume the current folder is the same folder where the DB is stored?
The folder I am trying to open is within the same folder as the DB, yes. So, they are both under ..\RMF Photos
 
cOuld alos user the UserProfile environment variable perhaps?
 
The folder I am trying to open is within the same folder as the DB, yes. So, they are both under ..\RMF Photos
Okay, in that case, you could try it this way:

Code:
strFolderPath = CurrentProject.Path & "\" & strfolderName
Hope it helps...
 
I am a bit late coming in here, but I would like to explain why "..\" didn't work.

The icon that you use to launch a particular app contains not only the path to MSACCESS.EXE but also the path to the APP file. If you copied the icon elsewhere, it still works in that new location but your default directory is no longer where the .ACCDB file resides. People forget what is in a "launch" icon and that leads to the confusion.
 

Users who are viewing this thread

Back
Top Bottom