Solved

How do I provide a window for user's to select specific files to be used in a process?

Posted on 2011-09-21
5
184 Views
Last Modified: 2012-05-12
I have the following code, allowing the user to identify a specific directory where source data exists:

 
Public Function GetDirectory()
 
'This script allows the user to select a directory,
'making it possible for results to be exported to that
'directory.
 
On Error GoTo ErrorHandler
 
   Dim strFolderPath As String
   Dim fd As Office.FileDialog
  
   'Create a FileDialog object as a Folder Picker dialog box.
   Set fd = Application.FileDialog(msoFileDialogFolderPicker)
  
   With fd
      .Title = "Identify the database(s) containing your source data"
      .ButtonName = "Select"
      .InitialView = msoFileDialogViewDetails
      .InitialFileName = "\\ShareServer\"
      If .Show = -1 Then
         strFolderPath = CStr(fd.SelectedItems.Item(1)) & "\"
      Else
         Debug.Print "User pressed Cancel"
         strFolderPath = ""
      End If
   End With
 
   GetDirectory = Trim(strFolderPath)
  
ErrorHandlerExit:
   Exit Function
 
ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
   Resume ErrorHandlerExit
 
End Function

Open in new window


I need to adapt it, allowing the user to identify the specific database to be used for the source data.  Can someone help me out with this?  Your help is greatly appreciated.

Thanks,

tebert0411
0
Comment
Question by:tebert0411
  • 3
5 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
Check out the code here
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
change this part

 Set fd = Application.FileDialog(msoFileDialogFolderPicker)


with


Set fd = Application.FileDialog(msoFileDialogFilePicker)
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
try this codes
Function getFile()
    
    Dim strFile As String
    Dim fd As Object
    Set fd = Application.FileDialog(3) 'msoFileDialogFilePicker
    
    With fd
        .Filters.Clear
        .Filters.Add "All Files", "*.*"
        .Filters.Add "Database", "*.mdb,*.accdb"
        .AllowMultiSelect = False
        .ButtonName = "Select File"
        .InitialFileName = "\\Fil-nw-902\737_systems\"
        .InitialView = msoFileDialogViewDetails
        .Title = "Identify the database(s) containing your source data"

        If .Show Then
            strFile = .SelectedItems(1)
            Else
            Exit Function
        End If
    End With
getFile = strFile
End Function

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
try this codes


Function getFile()
   
    Dim strFile As String
    Dim fd As Object
    Set fd = Application.FileDialog(3) 'msoFileDialogFilePicker
   
    With fd
        .Filters.Clear
        .Filters.Add "All Files", "*.*"
        .Filters.Add "Database", "*.mdb,*.accdb"
        .AllowMultiSelect = False
        .ButtonName = "Select File"
        .InitialFileName = "\\ShareServer\"
        .InitialView = msoFileDialogViewDetails
        .Title = "Identify the database(s) containing your source data"

        If .Show Then
            strFile = .SelectedItems(1)
            Else
            Exit Function
        End If
    End With
getFile = strFile
End Function

0
 

Author Closing Comment

by:tebert0411
Comment Utility
Thank you.  Never would have imagined it was something so simple.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now