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
185 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 119

Accepted Solution

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

 Set fd = Application.FileDialog(msoFileDialogFolderPicker)


with


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

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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 different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

914 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

13 Experts available now in Live!

Get 1:1 Help Now