Solved

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

Posted on 2008-10-16
6
2,665 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
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.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add records to a form to a table 11 40
Best way to create dynamic, short cut menu 7 27
Ms Access VBA Variables 6 27
Column Layout in Access Xp VBA Report 3 19
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

773 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