Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 875
  • 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.)



0
rspahitz
Asked:
rspahitz
  • 3
  • 2
1 Solution
 
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.
0
 
rspahitzAuthor Commented:
Yes it is completely documented in the help files.  How bizarre.

Do you have the API code?
0
 
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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  
0
 
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
0
 
rspahitzAuthor Commented:
Thanks for the link, rock...that's just bizarre.

And the code above works about right, dg.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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