?
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
?
195 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 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