?
Solved

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

Posted on 2014-02-25
6
Medium Priority
?
2,542 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 668 total points
ID: 39887658
On line 6 of your code, add:
fd.InitialFileName = "c:\example"

Open in new window

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 81

Assisted Solution

by:zorvek (Kevin Jones)
zorvek (Kevin Jones) earned 668 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 664 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
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 …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

807 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