FILE BROWSER IN MSACCESS
How to Browse for Folders or Files from MS-Access? If we can, then what do we do with the File(s) we bring into Access. Well, you can copy it from one place to the other for an example. Anyway let us get to work with the first part. But before that, a preview of the Run of our whole Project is given below and we will be working towards that with a small Form and with an On-Click Event Procedure:

This is the same Dialog Control that Opens up when you select the File(Open Menu Item. But here we got it when you click the Browse… Button given next to the Text-Box Control. When it comes up we are free to move around and select what we want and when you do the selected File will be inserted into the Text-Box control to the left of the Browse... Button.
Now let us get to work. Design a Small (or Big as you wish) Form as shown below and the Controls on the Form are already familiar to you as explained above except one. But I will list all of them below for info.
- Open a new Form and Create a Text-Box Control.
- Create a Command Button as shown in the above Design, display its Property Sheet and change the properties as given below:
- Now it is time to bring in the real hero element of our design: the Microsoft Common Dialog Control, to do that follow the procedure given below:
i) Change the Caption of the child-label to File Path Name:
ii). Display the property sheet of the Text-Box control and change the Name property to lbldb.
i) Name = cmdBrowse
ii) Caption = Browse…
- Select ActiveX Control from Insert Menu
- You will find a List of ActiveX Controls opens up, scroll down and select the Microsoft Common Dialog Control and Click OK. If you didn’t met any trouble on the way you will find a square shaped control sitting on your design surface. If your MS-Office installation is not properly done it is likely that you may end with a message like ‘this ActiveX DLL is not registered, re-install it’ etc.
- Copy the Following Visual Basic Code and paste it into our Form’s Code Module and complete the design by saving the Form.
Private Sub cmdBrowse_Click()
Dim VFile As String
On Error GoTo cmdBrowse_Click_Err
ChDrive ("C")
ChDir ("C:\")
cmDialog1.Filter = "All Files (*.*)|*.*| _
Text Files (*.txt)|*.txt|Excel WorkBooks (*.xls)|*.xls"
cmDialog1.FilterIndex = 1
cmDialog1.Action = 1
If cmDialog1.FileName <> "" Then
VFile = cmDialog1.FileName
Me!lbldb = VFile
End If
cmdBrowse_Click_Exit:
Exit Sub
cmdBrowse_Click_Err:
MsgBox Err.Description, , "cmdBrowse_Click"
Resume cmdBrowse_Click_Exit
End Sub
Now activate the Form and click on the Browse Button. The File Browsing Control that we have seen at the beginning should open up. Select a file from any location and click Open. The selected file with its complete location address is inserted into the Text Box control.
Download Demo Database
Command Button Animation
MsgBox with Office Assistant
Reminder Ticker Control
Labels: msaccess forms


















0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home