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



LVL 22
rspahitzAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

dqmqCommented:
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?
dqmqCommented:
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

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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

dqmqCommented:
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  
rockiroadsCommented:
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.
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.