Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fDialog - Opens at a User defined Folder

57 views
Skip to first unread message

Barry Edmund Wright

unread,
Jun 30, 2010, 12:48:33 PM6/30/10
to
Hi All,
I have the following code under a button click. The dialog opens to
display the "My Documents" folder. My question is how can I change it
to open at some other user specified folder, i.e., C:\Temp ? Thanks.

Dim varReturn As Variant
Dim varFile As Variant
Dim strDBDir As String
Dim strMsg As String
Dim db As Database
Dim varFileName As Variant
Dim tdf As TableDef
Dim intI As Integer
Dim intNumTables As Integer
Dim strProcName As String
Dim strFilter As String
Dim lngFlags As Long
Dim adhVerifyLinks As Boolean

Dim fDialog As Office.FileDialog

'Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Allow user to make multiple selections in dialog box.
.AllowMultiSelect = False

'Set the title of the dialog box.
.Title = "Please select one Access Database file"

'Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Access Databases", "*.MDB; *.ACCDB"

'Show the dialog box. If the .Show method returns True, the
'user picked at least one file. If the .Show method returns
'False, the user clicked Cancel.
If .Show = True Then
'Loop through each file selected and add it to the list box.
For Each varFile In .SelectedItems
varFileName = varFile
Next
Else
'MsgBox "You clicked Cancel in the file dialog box."
Exit Sub
End If
End With

Rich P

unread,
Jun 30, 2010, 12:41:30 PM6/30/10
to
Hi Barry, I use the Microsoft Office Library for OpenFileDialog -- as
follows:

Private Sub Command1_Click()
Dim v As Variant
Dim f As FileDialog

'--make a reference to: Microsoft Office 11.0 Object
'--Library (or whatever Office version is current)

Set f = Application.FileDialog(msoFileDialogOpen)

f.Filters.Add "Text Documents", "*.txt"
f.InitialFileName = "C:\1C"
f.Show
For Each v In f.SelectedItems
Debug.Print v
Next
End Sub

Rich

*** Sent via Developersdex http://www.developersdex.com ***

Salad

unread,
Jun 30, 2010, 1:33:38 PM6/30/10
to
Barry Edmund Wright wrote:

I have some old code...http://www.mvps.org/access/api/api0001.htm/

There's a flag called InitialDir. I passed a folder to the function and
have this line it it.
InitialDir:=varDirectory,

Barry Edmund Wright

unread,
Jun 30, 2010, 2:25:15 PM6/30/10
to

Thanks, worked like a charm - as suggested I just added the below line
to my code:
InitialFileName = "C:\Temp"

'Code Change


'Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Allow user to make multiple selections in dialog box.
.AllowMultiSelect = False

'Set the Dialog to open at a specified directory
.InitialFileName = "C:\Temp"

0 new messages