Results 1 to 8 of 8
  1. #1
    Ryobi is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    4

    Filtering single file usig dialog box

    Hello Everyone,



    I am wondering if somebody knows how to fitler a single file name in msaccess (2016) using dialog box. What I tried the following filter:

    .Filters.Add "Smaple.accdb", "*.accdb" which works except that also displays all accb files. I only need only show the single file "Smaple.accdb"

    Thank you



  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Try
    Code:
    .Filters.Add "Smaple.accdb"
    or if it insists on the second parameter
    Code:
    .Filters.Add "Smaple.accdb", "*.xcqrs"
    
    It's not likely to find that extension.

  3. #3
    Ryobi is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    4
    I had already tried .Filters.Add "Sample.accbd" and I got an error because it need the second paramenter. I also tired .Filters "Sample.Accdb", "Sample.Accdb" which give an error on the second paramenter.
    When I tried .Filters.Add "Sample.accdb", "*.xcqrs" I get no file listing. I used to used to because work when I a function below (It's the dialog function), but unfornately it does not work with Msaccess 2016. It does not
    open file selection option and it does get an message at all, added to fact that is function is for 32 bit and I using 64 bit Msaccess.


    strFilter = ahtAddFilterItem(strFilter, "Sample.accdb", "Sample.accdb")
    strInputFileName = ahtCommonFileOpenSave( _
    Filter:=strFilter, OpenFile:=True, _
    DialogTitle:="Please select data file...", _
    Flags:=ahtOFN_HIDEREADONLY)

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    The following code works in 32-bit & 64-bit Access

    Code:
     Set options for the dialog box.    Dim F As FileDialog
        Set F = Application.FileDialog(msoFileDialogFilePicker)
        F.title = "Locate the JSON file folder and click on 'Open' to select it" 'modify as appropriate
        
    ' Clear out the current filters, and add our own
        F.Filters.Clear
        F.Filters.Add "JSON files", "*.json"  'modify as appropriate
        
    ' Set the start folder. Open in default file folder if blank
        F.InitialFileName = Nz(Application.CurrentProject.Path & "\Files\", "C:\") 'modify as appropriate
        
    ' Call the Open dialog procedure.
        F.Show
    
    
    ' Return the path and file name.
        strFilePath = F.SelectedItems(1)
        
        Me.FileName = Mid(strFilePath, InStrRev(strFilePath, "\") + 1)
        strFile = Me.FileName
        Me.FolderPath = Left(strFilePath, Len(strFilePath) - Len(strFile) - 1)
        
        strFilename = Left(strFile, InStr(strFile, ".") - 1)
    However that doesn't solve your issue of filtering for an individual file
    I don't believe its possible to do so using a File...Open dialog
    By definition it filters for the file type you specify and shows all the files of that type
    If you specify a nonsense file type, you will get no results

    However I don't see the point of doing this anyway.
    If you know the file that you want to open, then scrap the file open dialog box
    Just open the file direct from the button click event
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    I agree with Colin. If you need to verify that a specific file exists before opening it, check out the DIR function.
    https://support.office.com/en-us/art...7-41e4513bba2e

  6. #6
    Ryobi is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    4
    ridder52,

    I have not tried what you wrote on the post, but will this do that later in the day. Regarding opening the the file directly, it may be possible that there my be other access files, for example the program that I have has
    two access file 1. program file Prg.accdb (This file a querys, forms and reports) and 2.) data file Prgdata.accdb (this file only has tables which are linked to Prg.accdb). By using this method I can alway modify the the program without affect the data, other wise you will comprise the data every time you modify the program (of course you could a rely on backup file and start again the modifications). I have a from in the program where I used the dialogbox to get file and linke (Not open) the tables from the datafile. I hope this means sense to you.

  7. #7
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Quote Originally Posted by Ryobi View Post
    ridder52,

    I have not tried what you wrote on the post, but will this do that later in the day. Regarding opening the the file directly, it may be possible that there my be other access files, for example the program that I have has
    two access file 1. program file Prg.accdb (This file a querys, forms and reports) and 2.) data file Prgdata.accdb (this file only has tables which are linked to Prg.accdb). By using this method I can alway modify the the program without affect the data, other wise you will comprise the data every time you modify the program (of course you could a rely on backup file and start again the modifications). I have a from in the program where I used the dialogbox to get file and linke (Not open) the tables from the datafile. I hope this means sense to you.
    Not really.
    You have a split database with Access FE and BE.
    Beyond that I can't understand what you're saying.
    Where does 'sample.accdb' come into this?
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  8. #8
    Ryobi is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    4
    I am sorry, but I change the file names when I explained the problem. I used Prg.accdb as the name of the program (front end) and Prgdata.accb as the data (backend). I was substituting Prgdata.accb with Sample.accdb (the data file). I could not find a way to show only that file so I did a work around. If they select any file other the one that the program needs they will received an error message. I have the code below.

    For Each varFile In .SelectedItems

    strInputFileName = Dir(varFile)
    If strInputFileName <> "Sample.accdb" Then
    MsgBox strInputFileName & " is not a valid file data file, please select Sample.accb", , "** No valid data File **"
    Exit Sub
    End If
    Next

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

Similar Threads

  1. Please Help With File Dialog Syntax
    By Chaser in forum Modules
    Replies: 8
    Last Post: 10-25-2017, 02:37 PM
  2. Late binding for MSO file dialog
    By Gina Maylone in forum Access
    Replies: 1
    Last Post: 01-26-2017, 04:58 AM
  3. Replies: 2
    Last Post: 11-12-2014, 06:31 PM
  4. Search for associated folders in file dialog box
    By john_billau in forum Programming
    Replies: 1
    Last Post: 01-27-2012, 03:48 PM
  5. How to get a load file dialog?
    By degras in forum Programming
    Replies: 4
    Last Post: 04-21-2011, 07:45 AM

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