Solved

User choose folder in Microsoft Access 2003

Posted on 2008-09-29
2
650 Views
Last Modified: 2013-11-28
In my system I want the user to be able to set the systemfolder so the database, templates and other files can be moved. Today I use only a textfield, but it would be nice if the user could choose folder by browsing to the folder with a dialogbox.

Thank you!
0
Comment
Question by:hke72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 22596403
This link has code and examples of using a folder browser:

http://www.mvps.org/access/api/api0002.htm
0
 
LVL 10

Expert Comment

by:therealmongoose
ID: 22597245
here's a useful function to achieve this. You can also set a default path to start the browse... Please note you need to set a reference to the shell32.dll (vba editor, tools, references... browse for the dll

To use the function, have a text field (or code variable) which is populated from a command button

me.txtfield = fncBrowseForFolder("Select a folder", "C:\")


Option Explicit
 
'Browse for folder function - allows selection of start folder (strRoot argument)
'requires reference to "c:\windows\system32\shell32.dll to be set in tools menu
 
Private Const BIF_RETURNONLYFSDIRS = &H1
 
Function fncBrowseForFolder(strTitle As String, strRoot As String) As String
 
On Error GoTo fncBrowseForFolder_error
 
    Dim shlObj As Shell
    Dim fldFolder As Folder
    Dim strFolder As String
    
    Set shlObj = New Shell
    Set fldFolder = shlObj.BrowseForFolder(hWndAccessApp, strTitle, BIF_RETURNONLYFSDIRS, strRoot)
    Set shlObj = Nothing
    
    strFolder = fldFolder.Self.Path
        
    Set fldFolder = Nothing
    
fncBrowseForFolder_exit:
 
    fncBrowseForFolder = strFolder
    Exit Function
    
fncBrowseForFolder_error:
    
    If Err.Number <> 91 Then 'object error = user pressed cancel - folder not created
        MsgBox Err.Number & " - " & Err.Description
    End If
    
    Resume fncBrowseForFolder_exit
    
End Function

Open in new window

0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question