S
Sigurd Bruteig
The following code works with VB6, but when I try to use it with Access 2002
I get an error message about the me. keyword. Can somebody thell me how to
change to fit Access VBA
Option Explicit
Private Declare Function SHGetPathFromIDList Lib "shell32" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32" _
(ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
pidl As Long) As Long
Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal pv As Long)
Private Sub Form_Load()
Debug.Print UserDeskTopFolder()
End Sub
Public Function UserDeskTopFolder()
' Excerpted and modified from:
' http://www.mvps.org/vbnet/index.html?code/shell/desktoplink.htm
Dim pidl As Long
Dim pos As Long
Dim sPath As String
'fill the pidl with the specified folder item
If SHGetSpecialFolderLocation(Me.hWnd, 0, pidl) = 0 Then
'initialize & get the path
sPath = String$(261, 0)
If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
'return folder
UserDeskTopFolder = Left$(sPath, InStr(sPath, Chr$(0)) - 1)
End If
End If
CoTaskMemFree pidl
End Function
Sigurd
I get an error message about the me. keyword. Can somebody thell me how to
change to fit Access VBA
Option Explicit
Private Declare Function SHGetPathFromIDList Lib "shell32" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32" _
(ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
pidl As Long) As Long
Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal pv As Long)
Private Sub Form_Load()
Debug.Print UserDeskTopFolder()
End Sub
Public Function UserDeskTopFolder()
' Excerpted and modified from:
' http://www.mvps.org/vbnet/index.html?code/shell/desktoplink.htm
Dim pidl As Long
Dim pos As Long
Dim sPath As String
'fill the pidl with the specified folder item
If SHGetSpecialFolderLocation(Me.hWnd, 0, pidl) = 0 Then
'initialize & get the path
sPath = String$(261, 0)
If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
'return folder
UserDeskTopFolder = Left$(sPath, InStr(sPath, Chr$(0)) - 1)
End If
End If
CoTaskMemFree pidl
End Function
Sigurd