Can't save using file dialog

Posted on 2006-04-03
Last Modified: 2010-05-18
Using Access 2002, the Set line fails:

    Dim dlgSave As Office.FileDialog

    Set dlgSave = Application.FileDialog(Office.msoFileDialogSaveAs) ' generates error

Error=445, "Object doesn't support this action"

It works with the other 3 msoFileDialog options, but not SaveAs (and not with a "2" in parentheses.)

Does anyone else get this error?

How can I fix this or what is the best work-around without building my own window?

(If it makes a difference, I'm running on Windows 2000 with service packs up to date.)

Question by:rspahitz
    LVL 42

    Expert Comment

    I don't believe the SaveAs option of FileDialog object is supported under Access.  In the past, I've resorted to the win32 API.
    LVL 22

    Author Comment

    Yes it is completely documented in the help files.  How bizarre.

    Do you have the API code?
    LVL 42

    Accepted Solution

    Here's the function I have used.   Will need to get back to you on the function declarative

    ' Function FileSaveFileAs
    '   Inputs: SearchPath - Initial Path to set dialog to
    '           FileFilter - string pairs to identify the searchable file extensions.
    '           Title      - Title for dialog box
    '   Outputs:Returns the full path to Database.
    '   Comments: Displays the Open dialog box for the user to locate
    '             a file.
    Public Function DialogFileSaveAs(Optional SearchPath As String _
                  , Optional FileFilter As String = "All Files" & vbNullChar & "*.*" & vbNullChar _
                  , Optional Title As String = "Save File As" _
                  , Optional Extension As String = "") As String
        Dim i As Integer
        Dim j As Integer
        Dim head As String
        Dim tail As String
        'Dim myPath As String
        Dim of As OPENFILENAME
        Dim intRet As Integer
        Dim strFile As String * 512
        'split search path into into pathname and filename
        'myPath = SearchPath
        i = InStrRev(SearchPath, "\")
        If i > 1 Then head = Left$(SearchPath, i - 1)
        tail = Mid$(SearchPath, i + 1)
        ' Set options for the dialog box.
        of.lpstrTitle = Title
        of.lpstrInitialDir = head
        of.lpstrFile = tail & String(512 - Len(tail), 0)
        of.lpstrFilter = FileFilter & vbNullChar
        of.nFilterIndex = 0
        of.lpstrDefExt = Extension           'extension to be applied if none is entered
        ' Initialize some parts of the structure.
        of.hWndOwner = Application.hWndAccessApp
        of.hInstance = 0
        of.lpstrCustomFilter = 0
        of.nMaxCustrFilter = 0
        of.lpfnHook = 0
        of.lpTemplateName = 0
        of.lCustrData = 0
        of.nMaxFile = 511
        of.lpstrFileTitle = String(512, 0)
        of.nMaxFileTitle = 511
        of.Flags = 0
        of.lStructSize = Len(of)
        intRet = GetSaveFileName(of)
        If intRet Then
          DialogFileSaveAs = Trim(Left(of.lpstrFile, InStr(of.lpstrFile, vbNullChar) - 1))
        End If
    End Function
    LVL 42

    Expert Comment

    OK, declare the following at the top of your module that contains the DialogFileSaveAs function.

    Private Type OPENFILENAME
        lStructSize As Long
        hWndOwner As Long
        hInstance As Long
        lpstrFilter As String
        lpstrCustomFilter As Long
        nMaxCustrFilter As Long
        nFilterIndex As Long
        lpstrFile As String
        nMaxFile As Long
        lpstrFileTitle As String
        nMaxFileTitle As Long
        lpstrInitialDir As String
        lpstrTitle As String
        Flags As Long
        nFileOffset As Integer
        nFileExtension As Integer
        lpstrDefExt As String
        lCustrData As Long
        lpfnHook As Long
        lpTemplateName As Long
    End Type

    Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
        "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Boolean  
    LVL 65

    Expert Comment

    dqmq is right, FileSaveAs was not designed to be used for Microsoft Access. God knows why, it works fine in other office products like Word and Excel. You can see this from reading this support article from MS

    Use the Win32 API functions, as provided
    LVL 22

    Author Comment

    Thanks for the link, rock...that's just bizarre.

    And the code above works about right, dg.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now