Using the File View Dialog Box in Access VBA

I saw this topic How do I show the "Open File" Dialog in Access 2007 VBA? and I like the solution that does not use links, however I cannot figure out how to display the path to the file that the user has selected. someone can explain

Thank you very much

this is the part I'm talking about

Dim f As Object Set f = Application.FileDialog(3) f.AllowMultiSelect = True f.Show MsgBox "file choosen = " & f.SelectedItems.Count 
+4
source share
1 answer

First of all, you should always use strong typed variables whenever possible. In this case, you can replace Object with Office.FileDialog .

To display the paths for each selected file, you need to loop through the SelectedItems collection. For example, you would add the following code:

 Dim f As Office.FileDialog Set f = Application.FileDialog(3) f.AllowMultiSelect = True ' Show the dialog. If the method returns True, the user picked at least one file. ' If the method returns False, the user clicked Cancel. If f.Show Then MsgBox f.SelectedItems.Count & " file(s) were chosen." ' Display the full path to each file that was selected Dim i As Integer For i = 1 To f.SelectedItems.Count MsgBox f.SelectedItems(i) Next i End If 

Please note that FileDialog also has other properties that you can set if configuration is required. For example, the .Title property allows .Title to specify the title that will be displayed in the title of the dialog in the title bar. You can also specify a filter using the .Filter property, which limits the type of files that the user can see and select in the dialog box. For example, if you want to limit the selection to only available databases, you can add the following code:

 ' Clear out the current filters f.Filters.Clear ' Add a few custom filters f.Filters.Add "Access Databases", "*.mdb" f.Filters.Add "All Files", "*.*" 
+5
source

Source: https://habr.com/ru/post/1337271/


All Articles