Results 1 to 3 of 3
  1. #1
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451

    FileDialog filter add


    I'm having a hard time and needing some help. i have a filedialog picker that i'm using and trying to get it to filter down to just access files but this one line is giving me a hard time, sometimes it works and sometimes gives me a runtime error 438 object doesn't support this property or method. The line always highlighted is .Filters.Add "Access", "*.accdb", 1

    Code:
    Public Function GetFileFolder(strType As String, strTitle As String) As String
        'Add "Microsoft Office 14.0 Object Library" in references
        Dim fDialog As Office.FileDialog
        Dim varFile As Variant
        Dim typeOfPicker As Integer
        
        Select Case strType
            Case "folder"
                typeOfPicker = msoFileDialogFolderPicker
            Case "file"
                typeOfPicker = msoFileDialogFilePicker
        End Select
        
        Set fDialog = Application.FileDialog(typeOfPicker)
        With fDialog
            .Title = strTitle
            .Filters.Clear       
            .Filters.Add "Access", "*.accdb", 1 'Having a hard time with the filter add,
            .FilterIndex = 1
            .AllowMultiSelect = False
            .InitialFileName = "time1_be.accdb" 'filestart
            
            If .Show = True Then
                If .SelectedItems.Count = 0 Then
                    GetFileFolder = ""
                End If
                
                For Each varFile In .SelectedItems
                    GetFileFolder = varFile
                Next
            Else
                GetFileFolder = ""
            End If
        End With
    End Function
    is there a syntax error that i'm missing? i do have my library set to Microsoft office 16 object library. is there a better way to get my filter to only show accdb files?

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    my guess is that filters would not apply to folders and you are getting the error when strType="folder"

  3. #3
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    Sorry, I've been meaning to get back and close this. Ajax, i must confess, after you replied i had done some changes and could not find the instance of the filedialog that was giving me the error. when i saw your reply it did make since and i wouldn't doubt it one bit if i had tried using the folder option instead of file. thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-07-2016, 07:11 AM
  2. FileDialog with filters
    By fritesmodern in forum Programming
    Replies: 6
    Last Post: 05-08-2015, 08:28 AM
  3. Open .csv with fileDialog then TransferSpreadsheet
    By corptkm in forum Programming
    Replies: 1
    Last Post: 01-27-2015, 11:43 AM
  4. FileDialog Question
    By uaguy3005 in forum Programming
    Replies: 5
    Last Post: 06-27-2012, 02:01 PM
  5. FileDialog
    By Tomfernandez1 in forum Programming
    Replies: 9
    Last Post: 04-13-2011, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums