Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2002
    Location
    London, UK
    Posts
    22

    Unanswered: filedialog not working in mde

    I have the following in my code to open a file dialog for selecting a file:


    Dim Fd as FileDialog

    set Fd = FileDialog(msoFileDialogFilePicker)
    Fd.show


    this code works fine when running as an mdb, however when the database is compiled to an mde it comes up with the following error:


    Method 'FileDialog' of object '_Application' failed


    the error is happening on the 'set Fd =....' line.

    Any ideas/solutions gratefully received

    Andy

  2. #2
    Join Date
    Nov 2001
    Posts
    336
    Sorry, It's a part of Office XP. Didn't have a chance to work with it.

    If you need a working solution, then use code posted here:

    http://www.mvps.org/access/api/api0001.htm

    HTH

  3. #3
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    My very first post on this forum dealt with the common dialog box and the problems we've encountered with using the ActiveX version.

    I posted some code which has proved reliable with .mde's--check it at this link:

    CommonDialogBox Code

  4. #4
    Join Date
    Mar 2002
    Location
    London, UK
    Posts
    22
    Thanks for the help. The method from PracticalProgram works a treat.

    Many Thanks

    Andy

  5. #5
    Join Date
    Mar 2002
    Location
    London, UK
    Posts
    22
    Can the method provived by PracticalProgram be used for a save dialog box?

    What do I have to do to use it as a save dialog, or what other method can I use?

  6. #6
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    Sure,

    One of the options in this function is to change the button caption of the "Open" button. You can change it to "Save."

    The function will not accomplish the actual save, you've got to do that, but it will return the path and file name which you can use for your save routine.

  7. #7
    Join Date
    Mar 2002
    Location
    London, UK
    Posts
    22
    I tried setting the button caption to be Save but when I click on it nothing happens. Are there any of the parameters I should leave out for a save dialog to work correctly?

  8. #8
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    All this function does is return a file path/name.

    That is all.

    If you put "Save" on the button, it is not going to save, it is just going to return a file path/name.

    If you put "Open" on the button, it is not going to open anything, it is just going to return a file path/name.

    As I said in my last post, the function does not actually do anything beyond returning a file path/name.

    You've got to do the rest.

  9. #9
    Join Date
    Mar 2002
    Location
    London, UK
    Posts
    22
    Sorry, I may not have explained myself correctly. I am aware that all this function does is to return a filename. I am using it to allow the user to select the name and location of the file that they want to export a report to.

    The code I have is as follows:

    ########

    Private Sub btnExport_Click()
    'Code to expor the report to Excel and then sort out its formatting

    Dim strFileName As String

    strFileName = basCommonDialog(0, "MS Excel (*.XLS)", "Report.xls", "Export report to", "Save", "c:\temp\")
    MsgBox strFileName 'temporary
    strFileName = "c:\temp\report.xls" 'temporary

    If strFileName <> "" Then
    strButtonClicked = "Export"
    RunTheReport 'open the report
    Else
    MsgBox "You did not enter a filename"
    End If 'if strFile

    End Sub

    #############

    when I run this the file dialog opens but when I type in the name I want for my file and press Save, nothing happens. The file dialog remains on screen and no pathname is returned.

    Do you have to pass in a different value other than 0 to allow you to enter the name of a file that doesn't exist (in the case of saving something new).

  10. #10
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    Here, I've modified it to accomplish what you need. You pass an additional parameter: True for an Open, False for a Save.

    I didn't have time to distill this to some simpler code, but it should do for now.

    By the way, it looks like this function originated with Ken Getz. He's written many excellent texts. I would recommend all to everyone.

    Code:
    Option Compare Database
    Option Explicit
    
    Type adh_accOfficeGetFileNameInfo
    hwndOwner As Long
    strAppName As String * 255
    strWindowCaption As String * 255
    strButtonCaption As String * 255
    strFileName As String * 4096
    strInitialDirectory As String * 255
    strFileFilter As String * 255
    lngFilterIndex As Long
    lngView As Long
    lngFlags As Long
    End Type
    
    Declare Function adh_accOfficeGetFileName Lib "msaccess.exe" Alias "#56" (gfni As adh_accOfficeGetFileNameInfo, ByVal fopen As Integer) As Long
    
    Function basCommonDialog(Optional Flags As Long = 0, Optional FileFilter As String = "", Optional FileName As String = "", Optional WindowCaption As String = "", Optional ButtonCaption As String = "", Optional InitialDirectory As String = "", Optional OpenOrSave As Boolean = True) As Variant
    
        Dim gfni As adh_accOfficeGetFileNameInfo
        Dim fopen As Integer
        
        gfni.lngFlags = Flags '0=File, 32=Directory
        gfni.strWindowCaption = WindowCaption & vbNullChar
        gfni.strButtonCaption = ButtonCaption & vbNullChar
        gfni.strFileName = FileName & vbNullChar
        gfni.strInitialDirectory = InitialDirectory & vbNullChar
        gfni.strFileFilter = FileFilter & vbNullChar
    
        If OpenOrSave = True Then
            If adh_accOfficeGetFileName(gfni, True) = 0 Then
                basCommonDialog = Trim(IIf(InStr(gfni.strFileName, vbNullChar) = 0, gfni.strFileName, Left$(gfni.strFileName, InStr(gfni.strFileName, vbNullChar) - 1)))
            End If
        Else
            If adh_accOfficeGetFileName(gfni, False) = 0 Then
                basCommonDialog = Trim(IIf(InStr(gfni.strFileName, vbNullChar) = 0, gfni.strFileName, Left$(gfni.strFileName, InStr(gfni.strFileName, vbNullChar) - 1)))
            End If
        End If
    
    End Function

  11. #11
    Join Date
    Mar 2002
    Location
    London, UK
    Posts
    22
    Thanks very much.

    Just out of interest how did you know about the #56 function. Is there any documentation about the internal functions of access similar to this one?

  12. #12
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    As I said, this is, basically, from Ken Getz's Access book.

    I encourage everyone to buy his books cause they have great pieces of code in them, like this code.

    The original, from the book, has a lot more code in it, but doesn't do anything different. The open, versus save, functionality is mentioned in Ken's book.

  13. #13
    Join Date
    Jan 2003
    Posts
    1
    Originally posted by PracticalProgram
    My very first post on this forum dealt with the common dialog box and the problems we've encountered with using the ActiveX version.

    I posted some code which has proved reliable with .mde's--check it at this link:

    CommonDialogBox Code
    **************

    This link doesn't work anymore
    Would you please repost it

    thanx

  14. #14
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    Originally posted by ACCWIZ
    **************

    This link doesn't work anymore
    Would you please repost it

    thanx
    Look above, three postings.

    The code is there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •