?
Solved

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

Posted on 2008-10-16
6
Medium Priority
?
2,677 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Suggested Courses

752 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