Solved

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

Posted on 2014-02-25
6
1,603 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

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.

Question has a verified solution.

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

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
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…

911 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

21 Experts available now in Live!

Get 1:1 Help Now