Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
199 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
[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
  • 3
5 Comments
 
LVL 48

Expert Comment

by:Dale Fye
ID: 36573559
Check out the code here
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 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