Results 1 to 2 of 2
  1. #1
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067

    File Directory in VBA

    It's been several years since I've done this and I don't remember exactly how I did it. I need to be able to prompt a user for a file. Where the user gets a dialog that looks and functions similar to Windows Explorer allowing the user to select the required file. Giving the path and file name of the file required. I just can't remember how I did it. It was in Access 2000 or 2003. Hasn't come up since until now. Can anybody point me in the right direction. Thought it was the File System Object but looking at the samples I'm not so sure anymore.

    Thanks

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Here is a function I wrote to do just that:

    Code:
    Function Select_File(Current_Location As Variant, Dialog_Title As String) As Variant
      On Error GoTo errproc
      Dim CurrentProcedure As Variant
      CurrentProcedure = "Select_File"
      Dim fd As FileDialog
      Dim ReturnPath As Variant, ReturnValue As Integer
      Set fd = Application.FileDialog(msoFileDialogFilePicker)
      '
      '  Initialize the directory with the current value
      '
      If IsNull(Current_Location) Then
        fd.InitialFileName = "C:\"
      Else
        fd.InitialFileName = Current_Location
      End If
      fd.title = "Select a file for " & Dialog_Title
      ReturnValue = fd.Show
      If ReturnValue <> 0 Then
        '
        ' Dialog was not closed with "Cancel"
        '
    '    MsgBox "Returned Value = " & ReturnValue
        Select_File = fd.SelectedItems(1)
      Else
        '
        ' Return value is the same as the initial value
        '
        Select_File = Current_Location
      End If
      Set fd = Nothing
       
      Exit Function
    errproc:
       ' whatever error processing you need
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 08-15-2015, 10:09 AM
  2. Replies: 1
    Last Post: 01-17-2014, 09:51 AM
  3. Open file from current Directory
    By mathanraj76 in forum Programming
    Replies: 3
    Last Post: 11-26-2013, 10:35 PM
  4. Replies: 10
    Last Post: 10-07-2013, 08:20 AM
  5. Parse a File from a Directory and write data to table
    By galahad in forum Database Design
    Replies: 0
    Last Post: 04-23-2009, 08:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums