Using msoFileDialogFilePicker  when file doesnt exist

Posted on 2008-02-01
Medium Priority
Last Modified: 2013-11-27
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
        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)
         FileNameArray(0) = ""
    End If
    GetFileName = CStr(FileNameArray(0))
    'For Each filename In FileNamearray
    '    Debug.Print filename
    'Next filename
End Function

Open in new window

Question by:larrydare
LVL 86

Accepted Solution

Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 800 total points
ID: 20802318
You'll need to abandon the FileDialog object and use API calls to get what you want ...


LVL 34

Assisted Solution

jefftwilley earned 800 total points
ID: 20802958
Terry Kreft wrote a nice function as well to browse for a folder vs a specific file

Here's additional support for you



Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Beware when using the ListIndex and the Column() properties of a listbox in Access 2007.  A bug has been identified in the Access 2007 listbox code which can cause the .ListIndex property to return a -1, and the .Columns(#) property to return a NULL…
When we develop an application in Ms Access 2016 we should also try to protect the queries, macros and table links. I know I may not have a permanent solution but for novice users, they will not manage to break your application. Below is the detail …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

621 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