Solved

File open dialog box, Get the file path to textbox?

Posted on 2008-10-16
6
2,667 Views
Last Modified: 2013-11-28
How to click a button then pop up the dialog box, then allow to select a file and get this file path to textbox?
0
Comment
Question by:Uncochen
  • 2
  • 2
  • 2
6 Comments
 
LVL 26

Expert Comment

by:dannywareham
ID: 22736803
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 22736812
The function Test_It() does the work.

just call that function and the file is returned as a msgbox.
You can use the variable in your text box:

Me.textbox = GetOpenFile

:-)
0
 

Author Comment

by:Uncochen
ID: 22738794
It can not work, is possible sent me a sample please?
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 23

Expert Comment

by:irudyk
ID: 22742802
Try the following code on the button control's On Click event
'change ButtonCommand to the actual name of the button control
Private Sub ButtonCommand_Click()
 
With Application.FileDialog(msoFileDialogFilePicker)
    'change Text1 to the actual name of the Textbox control on your form
    If .Show Then Text1 = .InitialFileName Else Text1 = Null
End With
    
End Sub

Open in new window

0
 

Author Comment

by:Uncochen
ID: 22746203
Hi irudyk,
I did try above code. it work ok, can open the dialog to open the file, but it only can got the folder path, can not got the file name! I don't know why?
0
 
LVL 23

Accepted Solution

by:
irudyk earned 500 total points
ID: 22746687
Sorry, that would be because I thought it was the folder name where the selected file resided was what you wanted.  To get the selected file name use the following revised code (which also sets it so that only 1 file can be selected):
'change ButtonCommand to the actual name of the button control
Private Sub ButtonCommand_Click()
 
With Application.FileDialog(msoFileDialogFilePicker)
    .AllowMultiSelect = False
    'change Text1 to the actual name of the Textbox control on your form
    If .Show Then Text1 = .SelectedItems(1) Else Text1 = Null
End With
    
End Sub

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

792 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