From: Barry Edmund Wright on
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
From: Rich P on
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 ***
From: Salad on
Barry Edmund Wright wrote:

> 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

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,
From: Barry Edmund Wright on
On Jun 30, 12:41 pm, Rich P <rpng...(a)aol.com> wrote:
> 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 Developersdexhttp://www.developersdex.com***

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"

'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