File browse in MS Access Form
This article is about to open the file browser on Microsoft Access using VBA code. We can open the file browser either using by Active X control or using msoFileDialogFilePicker property of File Dialog. The collection of the SelectedItems of FileDialog object contains the paths to the selected files and using VBA code we are able to insert the selected file path into textbox.
For implementation of File browser firstly we have to create the Form with following design as shown in Fig 1.1.
On button click we have to write VBA code in Microsoft Visual Basic Editor and also add reference the Microsoft Office 14.0 Object Library for support FileDialog method. After writing the code we have to test the code on Form view. As we click on the browse button the File browser window will open and we can select any supportive file as shown in Fig 1.2.
After selection of file on browsing window the path of file will automatically fetched by textbox as shown in Fig 1.3.
VBA CODE :
Option Compare Database Private Sub Command5_Click() With Application.FileDialog(msoFileDialogFilePicker) Dim BROWSEFILE As String Dim BROWSEITEM As Variant .Show .Filters.Add "All Files", "*.*" For Each BROWSEITEM In .SelectedItems BROWSEFILE = BROWSEITEM Me![txtBox] = BROWSEFILE Next BROWSEITEM End With End Sub
It is advised that the information provided in the article should not be used for any kind formal or production programming purposes as content of the article may not be complete or well tested. Access Guru will not be responsible for any kind of damage (monetary, time, personal or any other type) which may take place because of the usage of the content in the article.
Copyright © 2019 ERP Makers