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
190 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)
ID: 36573559
Check out the code here
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 36573623
change this part

 Set fd = Application.FileDialog(msoFileDialogFolderPicker)


with


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

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36573734
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36573738
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
ID: 36573741
Thank you.  Never would have imagined it was something so simple.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

685 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