Combo box to select file names

Looking for a way to have a combo box act like explorer searcing directories and when I identify a file to link to the record, click on it and it saves the link / file & path name
rogerdjrAsked:
Who is Participating?
 
Helen FeddemaConnect With a Mentor Commented:
Here is some code to open a FileDialog object as a FilePicker, and save the selected file name to a textbox on a form:
Public Function SelectFile() As String
'Requires Office XP (2002) or higher
'Requires a reference to the Microsoft Office Object Library
'Created by Helen Feddema 3-Aug-2009
'Last modified 3-Aug-2009

On Error GoTo ErrorHandler

   Dim fd As Office.FileDialog
   Dim varSelectedItem As Variant
   Dim strFileNameAndPath As String
   
   'Create a FileDialog object as a File Picker dialog box.
   Set fd = Application.FileDialog(msoFileDialogFilePicker)
   
   With fd
      'Set AllowMultiSelect to True to allow selection of multiple files
      .AllowMultiSelect = False
      .Title = "Browse for File"
      .ButtonName = "Select"
      .Filters.Clear
      .Filters.Add "Documents", "*.doc; *.txt", 1
      .InitialView = msoFileDialogViewDetails
      If .Show = -1 Then
         'Get selected item in the FileDialogSelectedItems collection
         For Each varSelectedItem In .SelectedItems
            strFileNameAndPath = CStr(varSelectedItem)
         Next varSelectedItem
      Else
         Debug.Print "User pressed Cancel"
         strFileNameAndPath = ""
      End If
   End With
   
   SelectFile = strFileNameAndPath
   Me![txtFileName].value = strFileNameAndPath

ErrorHandlerExit:
   Set fd = Nothing
   Exit Function

ErrorHandler:
   MsgBox "Error No: " & Err.Number _
      & " in SelectFile procedure; " _
      & "Description: " & Err.Description
   Resume ErrorHandlerExit

End Function

Open in new window

0
 
SiddharthRoutCommented:
Where is the combobox?

Sid
0
 
SiddharthRoutCommented:
aikimark: Is the combo in Access?

Sid
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
SiddharthRoutCommented:
But when I replied there was only "Microsoft Applications"?

Sid
0
 
SiddharthRoutCommented:
Maybe OP added 'Access' Later?

Sid
0
 
SiddharthRoutCommented:
Ah! How dumb of me? lolzzz

Yes I missed that. Thanks.

Sid
0
 
SheilsCommented:
The sample DB from this site should give you a good start:

http://www.lebans.com/callbackbrowser.htm
0
 
rogerdjrAuthor Commented:
Public Function SelectFile() As String

Works great - is there a way to "preset" the function so it starts at a selected path?

Thanks
0
 
aikimarkCommented:
Add a static string variable that contains the path.
Near the top of the routine check the length of the variable.  If = 0 then initialize it with a default path.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.