Solved

Combo box to select file names

Posted on 2011-02-18
12
1,026 Views
Last Modified: 2013-11-28
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
0
Comment
Question by:rogerdjr
12 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34932691
Where is the combobox?

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34932874
aikimark: Is the combo in Access?

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34932907
But when I replied there was only "Microsoft Applications"?

Sid
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34932918
Maybe OP added 'Access' Later?

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34932922
Ah! How dumb of me? lolzzz

Yes I missed that. Thanks.

Sid
0
 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 500 total points
ID: 34933298
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
 
LVL 16

Expert Comment

by:Sheils
ID: 34938561
The sample DB from this site should give you a good start:

http://www.lebans.com/callbackbrowser.htm
0
 

Author Comment

by:rogerdjr
ID: 34943570
Public Function SelectFile() As String

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

Thanks
0
 
LVL 45

Expert Comment

by:aikimark
ID: 34944470
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

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

679 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