Using msoFileDialogFilePicker when file doesnt exist

An MSACCESS application generates an output file.
I would like to use FileDialog using msoFileDialogFilePicker

Works fine if I select an existing file to use.
But if I want to generate a brand new file,   I cant get it to accept the new name to pass back the directory and filename ?



Public Function GetFileName(Optional TitleStr As String = "Select Input Files to Use", _
Optional InitFileName As String = "C:\Documents and Settings\zn901a\Desktop\") As String
Dim fd         As FileDialog
Dim FileNameArray As Variant
Dim filename   As Variant
 
    ReDim FileNameArray(0)
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
    
    .InitialFileName = InitFileName
        .Title = TitleStr
        .InitialView = msoFileDialogViewList
 
        .AllowMultiSelect = False
        .Filters.Clear
       
        If .Show = -1 Then
            For Each filename In .SelectedItems
                FileNameArray(UBound(FileNameArray)) = filename
                ReDim Preserve FileNameArray(UBound(FileNameArray) + 1)
            Next filename
        End If
    End With
    If Not IsEmpty(FileNameArray(0)) Then
        ReDim Preserve FileNameArray(UBound(FileNameArray) - 1)
    Else
         FileNameArray(0) = ""
    End If
    GetFileName = CStr(FileNameArray(0))
    'For Each filename In FileNamearray
    '    Debug.Print filename
    'Next filename
End Function

Open in new window

larrydareAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You'll need to abandon the FileDialog object and use API calls to get what you want ...

http://www.mvps.org/access/api/api0001.htm

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jefftwilleyCommented:
Terry Kreft wrote a nice function as well to browse for a folder vs a specific file

Here's additional support for you

http://www.ammara.com/access_image_faq/browse_for_folder_dialog.html

J
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.