Solved

how to open a FileDialog in microsoft access 2013 on a specific location

Posted on 2014-02-25
6
1,678 Views
Last Modified: 2014-02-25
hi

i use this code on a form to open a file dialog
Function selectFile()
Dim fd As FileDialog, fileName As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'disable multiselect for one file selection
fd.AllowMultiSelect = False
 
If fd.Show = True Then
    fileName = fd.SelectedItems(1)
End If
 
'clear file dialog
Set fd = Nothing
 
'Return File name and path
selectFile = fileName
 
End Function

Open in new window


how can i set that the dialog box will show a specific location for example it's will show files on the  location "c:\example\"
0
Comment
Question by:bill201
6 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39887648
To open a file open dialog in a specific directory, change the default directory before showing the dialog. In this example I'm setting the default directory to the desktop:

   ChDir CreateObject("Wscript.Shell").SpecialFolders("Desktop")

Kevin
0
 

Author Comment

by:bill201
ID: 39887657
in what line should i put this line of code?
0
 
LVL 8

Accepted Solution

by:
N-W earned 167 total points
ID: 39887658
On line 6 of your code, add:
fd.InitialFileName = "c:\example"

Open in new window

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 81

Assisted Solution

by:zorvek (Kevin Jones)
zorvek (Kevin Jones) earned 167 total points
ID: 39887660
Before the line that shows the dialog.

Before this line would work:

ChDir CreateObject("Wscript.Shell").SpecialFolders("Desktop")
Set fd = Application.FileDialog(msoFileDialogFilePicker)

Kevin
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 166 total points
ID: 39887662
Function selectFile()
Dim fd As FileDialog, fileName As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'disable multiselect for one file selection

'ADD this line

fd.initialfilename =  "c:\example\"


fd.AllowMultiSelect = False
 
If fd.Show = True Then
    fileName = fd.SelectedItems(1)
End If
 
'clear file dialog
Set fd = Nothing
 
'Return File name and path
selectFile = fileName
 
End Function
0
 

Author Comment

by:bill201
ID: 39887663
thanks a lot for every one
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

813 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

8 Experts available now in Live!

Get 1:1 Help Now