[AccessD] Location of Desktop

Mitsules, Mark Mark.Mitsules at ngc.com
Tue Sep 2 15:03:28 CDT 2003


Amanda,

Here's what you need...taken from Microsoft Knowledge Base Article - 182606.

Mark
****************************************************
BEGIN CODE
****************************************************
Option Compare Database
Option Explicit

       ' Declare variables.
       Dim DesktopPath As String
       Dim StartMenuPath As String
       Dim WinPath As String
       Dim fNameOld As String
       Dim fNameNew As String

       ' Declare Public variables.
       Public Type ShortItemId
            cb As Long
            abID As Byte
       End Type

       Public Type ITEMIDLIST
            mkid As ShortItemId
       End Type

       ' Declare constants.
       Const CSIDL_TEMPLATES = &H15
       Const CSIDL_STARTMENU = &HB
       Const CSIDL_FAVORITES = &H6
       Const CSIDL_DESKTOPDIRECTORY = &H10

       ' Declare API functions.
       Public Declare Function SHGetPathFromIDList Lib "shell32.dll" _
          (ByVal pidl As Long, ByVal pszPath As String) As Long

       Public Declare Function SHGetSpecialFolderLocation Lib _
          "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder _
          As Long, pidl As ITEMIDLIST) As Long

       Function GetSpecialFolder(CSIDL As Long) As String

          Dim idlstr As Long
          Dim sPath As String
          Dim IDL As ITEMIDLIST

          Const NOERROR = 0
          Const MAX_LENGTH = 260

          On Error GoTo Err_GetFolder

          ' Fill the idl structure with the specified folder item.
          idlstr = SHGetSpecialFolderLocation _
             (Application.hWndAccessApp, CSIDL, IDL)

          If idlstr = NOERROR Then

               ' Get the path from the idl list, and return
               ' the folder with a slash at the end.
               sPath = Space$(MAX_LENGTH)
               idlstr = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath)

                  If idlstr Then
                    GetSpecialFolder = Left$(sPath, InStr(sPath, Chr$(0)) _
                      - 1) & "\"
                  End If

          End If

Exit_GetFolder:
           Exit Function
Err_GetFolder:
           MsgBox Err.Description, vbCritical Or vbOKOnly
           Resume Exit_GetFolder

       End Function


Sub Test()
   Dim strDesktopPath As String
   strDesktopPath = GetSpecialFolder(CSIDL_DESKTOPDIRECTORY)
   Debug.Print strDesktopPath
End Sub
****************************************************
END CODE
****************************************************

-----Original Message-----
From: Mitsules, Mark S. (Newport News) [mailto:mitsules_ms at nns.com] 
Sent: Tuesday, September 02, 2003 1:57 PM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] Location of Desktop


Amanda,

I've never used it, but I've seen this syntax referenced before. DesktopPath
= GetSpecialFolder(CSIDL_DESKTOPDIRECTORY)



Mark


-----Original Message-----
From: Amanda Allen [mailto:AJAllen at mail.wvu.edu] 
Sent: Tuesday, September 02, 2003 1:44 PM
To: <"Access Developers discussion and problem solving"
Subject: [AccessD] Location of Desktop


How do I reference the location of the desktop using VBA in MS Access?

I want to put a shortcut of the database on the user's desktop.

-- Amanda

_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


More information about the AccessD mailing list