Solved

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

Posted on 2008-10-16
6
2,661 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

760 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

16 Experts available now in Live!

Get 1:1 Help Now