Solved

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

Posted on 2008-10-16
6
2,674 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Independent Software Vendors: 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!

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.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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