Solved

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

Posted on 2014-02-25
6
1,532 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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

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.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
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 …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

706 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

17 Experts available now in Live!

Get 1:1 Help Now