<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener("load", function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <iframe src="http://www.blogger.com/navbar.g?targetBlogID=34083602&amp;blogName=LEARN+MS-ACCESS+TIPS+AND+TRICKS&amp;publishMode=PUBLISH_MODE_FTP&amp;navbarType=BLUE&amp;layoutType=CLASSIC&amp;searchRoot=http%3A%2F%2Fblogsearch.google.com%2F&amp;blogLocale=en_US&amp;homepageUrl=http%3A%2F%2Fwww.msaccesstips.com%2F" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="30px" width="100%" id="navbar-iframe" allowtransparency="true" title="Blogger Navigation and Search"></iframe> <div></div>
www.msaccesstips.com

LEARN MS-ACCESS TIPS AND TRICKS


International Response Fund

LEARN MS-ACCESS TIPS AND TRICKS

↑ Grab this Headline Animator

Your Ad Here
Tuesday, October 10, 2006

FILE BROWSER IN MSACCESS

SEARCHING FOR OTHER FILES FROM 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:
Common Dialogue control image

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.


  1. Open a new Form and Create a Text-Box Control.

  2. 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.

  3. Create a Command Button as shown in the above Design, display its Property Sheet and change the properties as given below:


  4. i) Name = cmdBrowse
    ii) Caption = Browse…

  5. 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:


  • 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.
Display the Property Sheet of the Common Dialog Control and change the Name property to cmDialog1. You can place it anywhere at your convenience, it will not be visible when you activate your Form.

  • 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:

6 Comments:

Anonymous Aécio Lemos said…

I know you posted this some 3 years ago but a client of mine needed maintenance in an Access application and this saved me a lot of time. Thank you for the tutorial and the SIMPLE way of making this work. Other tutorials were huge.

Thanks again!

March 17, 2009 7:42 PM  
Blogger Dracula77 said…

I like the form but it doesnt work, it gives me the error message" object doesnt support this property or method"
thanks.

June 17, 2009 8:33 PM  
Blogger a.p.r. pillai said…

You may try the following Code, if you are using MS-Access 2003. This sample code you can find on the Code Module of Employees Form in NorthWind.mdb database. The Program is run from the Add/Remove Button click on the Form.

Private Sub AddPicture_Click()
' Use the Office File Open dialog to get a file name to use
' as an employee picture.
getFileName
End Sub




Sub getFileName()
' Displays the Office File Open dialog to choose a file name
' for the current employee record. If the user selects a file
' display it in the image control.
Dim fileName As String
Dim result As Integer
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select Employee Picture"
.Filters.Add "All Files", "*.*"
.Filters.Add "JPEGs", "*.jpg"
.Filters.Add "Bitmaps", "*.bmp"
.FilterIndex = 3
.AllowMultiSelect = False
.InitialFileName = CurrentProject.path
result = .Show
If (result <> 0) Then
fileName = Trim(.SelectedItems.Item(1))
Me![ImagePath].Visible = True
Me![ImagePath].SetFocus
Me![ImagePath].Text = fileName
Me![FirstName].SetFocus
Me![ImagePath].Visible = False
End If
End With
End Sub

You may modify it to suit to your requirement.

Regards,

June 18, 2009 12:01 AM  
Anonymous Anonymous said…

Hi - could you add a demo database of your browser lesson to your site? Having a demo version to compare to my own would be really useful!! Thanks.

September 05, 2009 8:37 PM  
Blogger a.p.r. pillai said…

You may download a Demo Database from the following link:

http://www.msaccesstips.com/downloads/2006/10/file-browser.shtml

September 06, 2009 7:39 AM  
Anonymous Anonymous said…

Hi,

Thanks a lot!

The MS-Access 2002 example database contains the same code as the MS-Access 2003's. To find said database: http://support.microsoft.com/?scid=kb%3Ben-us%3B276376&x=20&y=10

Bye !

January 12, 2010 8:24 PM  

Post a Comment

Note:Comments subject to Review by Blog Author before displaying.

Links to this post:

Create a Link

<< Home


Creative Commons License
Learn MS-Access Tips and Tricks by msaccesstips.com is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 India License.



This Page is best viewed with 1280 x 1024 Resolution

   FEATURED LINKS
SITEMAP
Command Button Animation
3D Headings on Forms
MsgBox & Office Assistant
Reminder Ticker
MS-Access & E-Mails
Automated E-Mail Alerts
MsgBox with Options Menu
Colorful Command Buttons
Configure Lotus Notes
Alerts through Network
Running this site has become a costly affair as the revenue from Ads is not sufficient to support it. If you find these pages informative & useful and would like to extend a helping hand, then please do it here.





Link Back to us with this Button

Learn MS-Access

Copy and Paste this HTML Code in your Webpage


Add to Technorati Favorites

Programming Blogs - Blog Catalog Blog Directory
Powered by FeedBurner
Add to Google

Software
Computers blogs
TopOfBlogs




AddMe - Search Engine Optimization Submit Your Site Free!
Go BlogZ Ave Blogs
eBlogzilla Changing LINKS
LS Blogs Blogarama
blog search directory BlogUniverse
Find Blogs in Directory RSS Directory
blogskinny.com ShowcaseBlogs.com
Amfibi

Search Engine Optimization and SEO Tools
Dmegs Web Directory Takeaway for Sale Businesses For Sale
Free Submission Directory Free site submission

Free Listing
 





Free Page Rank Checker

AddThis Social Bookmark Button

Enter your email address:

Delivered by FeedBurner



Top Blogs


Microsoft Access is the Jewell among MS-Office suite of Applications. Its Security features are excellent and works fine in Network environment. MS-Access can link/upload data from any Data Source. Applications that you design should be user-friendly and visually pleasing too. Here I would like to share my experience in Microsoft Access Programming with you and I am sure that you will find them interesting too.

My Photo
Name: Ramachandran Pillai
Location: Cochin, India

I am not an Access Guru and not through MS-Access yet. More to learn and I don’t think that aspect has any end because others have their own style of using this tool. We can learn lot more tricks, other than what we already know, from others too. My programming skills in COBOL, BASIC, Turbo-C, dBase, FoxPro, Visual Basic & Basic HTML attained through self-learning. I wrote my first COBOL Program in 1975 for ICL1901, 3rd Generation Main Frame Computer. Worked as a Computer Operator (NCR VRX8555 Mainframe Machine upto 1990) with M/s. Y.B.A. Kanoo, Saudi Arabia. Started using MS-Access Ver.2 in 1996, when dBase III+ and Foxbase (later version Foxpro) were my favorite DBMS. During Last 13 Year period I have developed more than 45 In-House Applications (medium & small) under MS-Access for our Organization, a leading Automotive Company in Oman. All the Applications are fully Secured and runs under Windows Network. It is my pleasure to share my experience with others. Anything interesting that you would like to share with me, please do. My E-mail Address: aprpillai@msaccesstips.com


If you need a Demo of any of the Topic explained here, send me an E-mail to: aprpillai@msaccesstips.com
with the Topic Description, I shall try to send a sample database to you.


Access Tips | Email | Reports | Report Tricks | Graphs | Forms | Menus | Animation | Security | Internet | How TOs | Linking | Query | Progress Meter | Alerts | Process Tips | Access Functions |




Site Designed by:www.msaccesstips.com