Need function to get full path to My Documents folder

B

Bob Valentine

Group:

I need a function to get the full folder path to the "My Documents" folder.

I am using the function shown below, but it returns a path which is more
than the path to the "My Documents" folder.
This function returns the following path:
"C:\Documents and Settings\Owner\My Documents\Access Documents\My Documents



I do not have a "My Documents" folder in the Access Documents folder on my
computer so I don't know why the function is giving me an incorrect path. I
want the function to return "C:\Documents and Settings\Owner\My Documents"



Any help will be greatly appreciatied. Maybe you have a better function to
find the full path to a folder.



Thanks,

BobV



Here is the function:

Public Function adhFullPath(strName As String) As String

' MAX_PATH is defined by the Windows API.

Const MAX_PATH = 260

Dim lngLen As Long

Dim lngFilled As Long

Dim strBuffer As String

lngLen = MAX_PATH

Do

strBuffer = Space(lngLen)

lngFilled = GetFullPathName( strName, lngLen, strBuffer,
vbNullString)

If lngFilled > lngLen Then

lngLen = lngFilled

End If

Loop Until lngFilled < lngLen

adhFullPath = Left$(strBuffer, lngFilled)

End Function
 
D

Dirk Goldgar

In
Bob Valentine said:
Group:

I need a function to get the full folder path to the "My Documents"
folder.
I am using the function shown below, but it returns a path which is
more than the path to the "My Documents" folder.
This function returns the following path:
"C:\Documents and Settings\Owner\My Documents\Access Documents\My
Documents


I do not have a "My Documents" folder in the Access Documents folder
on my computer so I don't know why the function is giving me an
incorrect path. I want the function to return "C:\Documents and
Settings\Owner\My Documents"


Any help will be greatly appreciatied. Maybe you have a better
function to find the full path to a folder.



Thanks,

BobV



Here is the function:

Public Function adhFullPath(strName As String) As String

' MAX_PATH is defined by the Windows API.

Const MAX_PATH = 260

Dim lngLen As Long

Dim lngFilled As Long

Dim strBuffer As String

lngLen = MAX_PATH

Do

strBuffer = Space(lngLen)

lngFilled = GetFullPathName( strName, lngLen, strBuffer,
vbNullString)

If lngFilled > lngLen Then

lngLen = lngFilled

End If

Loop Until lngFilled < lngLen

adhFullPath = Left$(strBuffer, lngFilled)

End Function

That function is doing what it's supposed to, but it's not what you
want. Use the code posted here on The Access Web instead:

http://www.mvps.org/access/api/api0054.htm
API: Retrieving a Special Folder's location

After pasting the code, including the external function declarations and
defined constants, into a standard module, you can call the function
like this:

Dim strDocFolder As String

strDocFolder = fGetSpecialFolderLocation(CSIDL_PERSONAL)
 
B

Bob Valentine

Dirk:

Thank you for your quick response. That is exactly what I was looking for.
Thank you so much!

BobV
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top