Results 1 to 5 of 5
  1. #1
    stigmatized is offline Novice
    Windows 8 Access 2007
    Join Date
    Sep 2009
    Location
    Riyadh, Saudi Arabia
    Posts
    17

    Error in Open/Browse folder code in access 2010

    Hi guys,



    After the installation of the Access 2010, I am getting an error in my vba code in opening a folder. I think there is a compatibility issue between 2007 and 2010.

    This is the code that I used in 2007 version and it works fine.

    Code:
    Private Type BROWSEINFO
      hOwner As Long
      pidlRoot As Long
      pszDisplayName As String
      lpszTitle As String
      ulFlags As Long
      lpfn As Long
      LParam As Long
      iImage As Long
    End Type
    
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
    Private Const BIF_RETURNONLYFSDIRS = &H1
    
    Public Function BrowseFolder(szDialogTitle As String) As String
    Dim x As Long
    Dim bi As BROWSEINFO
    Dim dwIList As Long
    Dim szPath As String
    Dim wPos As Integer
      
        With bi
            .hOwner = hWndAccessApp
            .lpszTitle = szDialogTitle
            .ulFlags = BIF_RETURNONLYFSDIRS
        End With
        
        dwIList = SHBrowseForFolder(bi)
        szPath = Space$(512)
        x = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
        
        If x Then
            wPos = InStr(szPath, Chr(0))
            BrowseFolder = Left$(szPath, wPos - 1)
        Else
            BrowseFolder = vbNullString
        End If
    End Function

    The error is in this line

    Code:
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
     Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
    I just copied this code in the a forum to open a folder and I have no idea how to correct this.

    Please help me on this.


    Stigmatized

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    I use this. It can be used for ANYTHING.
    Pass it a file path, it will open it in file browser.
    Pass it a word doc, it will open Word....etc.

    Put the code in a module and call: OpenNativeApp "c:\folder\"


    Code:
    'Attribute VB_Name = "modNativeApp"
    Option Compare Database
    Option Explicit
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

  3. #3
    stigmatized is offline Novice
    Windows 8 Access 2007
    Join Date
    Sep 2009
    Location
    Riyadh, Saudi Arabia
    Posts
    17
    hi ranman,

    I tried to put this code to my vba but still there is an error was in this line

    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    it turns red the moment I put the code in the editor.


    stigmatized

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Was this running under 2007 on the same computer? "user32" expects a 32-bit operating system. When we upgraded to Windows7 and Access2010 and some users given 64-bit systems, I had to change code to use PtrSafe keyword.

    Private Declare PtrSafe Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal wRevert As Long) As Long
    Private Declare PtrSafe Function EnableMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long

    For alternative to Shell, consider http://allenbrowne.com/func-GoHyperlink.html
    or use FilePicker dialog.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    stigmatized is offline Novice
    Windows 8 Access 2007
    Join Date
    Sep 2009
    Location
    Riyadh, Saudi Arabia
    Posts
    17
    Quote Originally Posted by June7 View Post
    Was this running under 2007 on the same computer? "user32" expects a 32-bit operating system. When we upgraded to Windows7 and Access2010 and some users given 64-bit systems, I had to change code to use PtrSafe keyword.

    Private Declare PtrSafe Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal wRevert As Long) As Long
    Private Declare PtrSafe Function EnableMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long

    For alternative to Shell, consider http://allenbrowne.com/func-GoHyperlink.html
    or use FilePicker dialog.
    Yes. But my problem is if this will be open to 2007 with the 64-bit PtrSafe keyword, it will give an error. Some of my users are having 2007 version.

    I think I will use the FilePicker dialog instead.

    Thanks!!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Browse and Open Folder Based on Matching Form Field
    By Tomfernandez1 in forum Access
    Replies: 11
    Last Post: 02-26-2013, 01:04 PM
  2. Replies: 3
    Last Post: 02-22-2013, 06:41 AM
  3. Replies: 4
    Last Post: 09-18-2012, 11:30 PM
  4. Replies: 1
    Last Post: 06-21-2012, 07:58 PM
  5. open folder/Make new folder(example)-VBA Code
    By Madmax in forum Code Repository
    Replies: 3
    Last Post: 03-13-2012, 09:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums