Use a File Dialog in Microsoft Access

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
users need to select files in your application why not use a file dialog hi I am Phillip from Kokomo Netcom in this video I'm going to show you how to use the file dialog the common final look we know from countless applications inside your Microsoft Access application to let the user select files for data import or file names for data export or for whatever other reason you might need a file and this completes my series about importing text files into Microsoft Access if you haven't watched the previous videos and are interested in the topic I suggest you look for em I'm going to put a link somewhere in here and yeah that is the introduction for today let's get to work I already prepared a little bit here I've got a procedure that calls a dialog now we've got this dialog here and the user could enter file name and then use that dialog to import that file that all that works and if you want to know how that how I implemented that and then you should watch the video on that I'll put a link in here but typing a file name inside a text box that is not what most users would like so you need a proper dialogue to select the file here and now I will show how to implement that this is just my little form here and I add a tiny button next to that text box for the final name and we just put in three dots as the caption of that button that should be pretty intuitive to the user that he can click there to select I named the button a CMD select file and now I say I want to build an event in the cult builder this takes me right to the VBA editor and I switch to procedure of you only so that we do not get distracted by the other code inside that form and now I try to implement the file dialog to do that I need to add a reference on the object library from office I go to the Tools menu references and in this long list I scroll down to Microsoft Office Microsoft Office 15 object library and that version number in the middle might be different depending on what version of Office you got installed but it works all the same in all modern office versions since office 2010 and newer so now I can define a file dialog variable as final dialog and that is actually defined in that library I just referenced now we create an instance of the file dialog by saying application file dialog and I need to specify which kind of fire dialog I want I used this for opening and file for an text import so I use that MSL files either open and on a second I might the window a little bit wider so that will create the instance of the file dialog class now I need to set a couple of properties before I can use that I new need well this is optional but I like that very much and visual basic I can say with this object the final dialog FD and then I can just write dot and can refer to the properties of the file dialog right away without needing to write the FG dot all the time I want to select one file for import so I set the alarm multi select property to false and now the next thing we should think about which kind of files we want to allow the user to select and there is the filters collection in that class and that already contains quite a lot of office typical file names like Excel sheets and Access databases and Word documents and whatever we don't need all those so we just want to clear this collection before we continue so the filters collection is MD now we could select no file type at all but we want allow the user to actually select files so we use the add method to add file types to that filters collection and the first type I add is just any file that is the description and now here's the extensions property I think that is not properly named because it's actually a file mask so I need to enter something like star dot star for any file but it has to have this format I need to have a file name part the dot and then a pattern map for the extension and that is in first position in my list and I want to use this this file dialog to select an CSV file to import the data into access so I add a more specific field here and say the SV file I can write comma-separated file and that would have the pattern star dot CSV and sometimes people save their CSV files just with extension T extension txt so we can actually add several patterns in here we separate them by semicolon and now you can say dot txt to love for that as well and that is in a second position of my filters so we added the two different filters now I want to select a default filter that is done with the filter index method and we want to be the comma separated file should be our default filter and we refer to it by that index value right here at the end so I say filter index equals two and when basically done with the setup here now we can show the dialog what just need the show method and the show method returns and boolean value if the user clicks the Open button it will return true if the user cancels the dialog but we return false so we can't say if show the user has been confirmed the file open then we can assign the selected file to our text text box file name to its value property now with the dot we refer again to the file dialog and the selected items it could be multiple items if we have set allow multi select true but with that false for a multi select so that can be only one item and we can refer to that by the index one based index and so this will return the selected file to our text box now let's look if that works and here we go that is our file dialog and if I go browse to a directory more than armed the SV files in there look here is one I can say open and now the user can just click on the import file button and the import runs and as the import completed unbutton message box and that was actually the calling procedure now let's go back to that file dialog and that is basically it that's pretty simple and very user friendly way to select the file name in your application so we got the file dialog working now that is everything covered when I intended from the series solver series is complete nevertheless I suggest you subscribe to my channel and I'm going to publish lots and lots of other stuff I've so many ideas I can hardly decide where to start yeah thank you for watching have a good time bye bye [Music]
Info
Channel: codekabinett.com/en
Views: 19,780
Rating: 4.9398499 out of 5
Keywords: Microsoft Access, File Dialog, Select File, VBA, browse for files, Office File Dialog
Id: SYfdkdkkFRE
Channel Id: undefined
Length: 10min 31sec (631 seconds)
Published: Fri Dec 01 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.