• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 905
  • Last Modified:

Can't save using file dialog

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.)

  • 3
  • 2
1 Solution
I don't believe the SaveAs option of FileDialog object is supported under Access.  In the past, I've resorted to the win32 API.
rspahitzAuthor Commented:
Yes it is completely documented in the help files.  How bizarre.

Do you have the API code?
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 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

    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  
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 http://support.microsoft.com/?kbid=282335

Use the Win32 API functions, as provided
rspahitzAuthor Commented:
Thanks for the link, rock...that's just bizarre.

And the code above works about right, dg.
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

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now