Solved

Combo box to select file names

Posted on 2011-02-18
12
984 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
 
LVL 30

Expert Comment

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

Sid
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now