Solved Run-Time Error '490' (1 Viewer)

PatAccess

Registered User.
Local time
Today, 11:33
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:33
Joined
Oct 29, 2018
Messages
21,359
How about trying to use the full/absolute path (including the drive letter)? Just a thought...
 

PatAccess

Registered User.
Local time
Today, 11:33
Joined
May 24, 2017
Messages
284
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?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:33
Joined
Oct 29, 2018
Messages
21,359
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...
 

PatAccess

Registered User.
Local time
Today, 11:33
Joined
May 24, 2017
Messages
284
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
 

Isaac

Lifelong Learner
Local time
Today, 08:33
Joined
Mar 14, 2017
Messages
8,738
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.
 

PatAccess

Registered User.
Local time
Today, 11:33
Joined
May 24, 2017
Messages
284
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
 

Isaac

Lifelong Learner
Local time
Today, 08:33
Joined
Mar 14, 2017
Messages
8,738
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.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:33
Joined
Oct 29, 2018
Messages
21,359
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).
 

PatAccess

Registered User.
Local time
Today, 11:33
Joined
May 24, 2017
Messages
284
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:33
Joined
Oct 29, 2018
Messages
21,359
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?
 

PatAccess

Registered User.
Local time
Today, 11:33
Joined
May 24, 2017
Messages
284
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:33
Joined
Sep 21, 2011
Messages
14,056
cOuld alos user the UserProfile environment variable perhaps?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:33
Joined
Oct 29, 2018
Messages
21,359
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...
 

PatAccess

Registered User.
Local time
Today, 11:33
Joined
May 24, 2017
Messages
284
Okay, in that case, you could try it this way:

Code:
strFolderPath = CurrentProject.Path & "\" & strfolderName
Hope it helps...
Yes that did it.
Thank you so much!!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:33
Joined
Feb 28, 2001
Messages
27,004
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

Top Bottom