<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
Friday, December 14, 2007

Find or Filter Data on Form

When I started learning Microsoft Access in 1996 the first challenge that I have faced was how to find a particular record on the Data Editing Screen or Filter a group of records on some condition.


I was asked to develop a System for the Vehicles Division of our Company, for tracking pending Orders and Receipts of Heavy Equipments and Vehicles. If I am the one who is going to use the System, then some how I could manage to find the information that I want to work with and nobody will know how much time I spent for doing that. But it is going to be used by someone else and it is my job to make it as user friendly as possible. Even though I have good knowledge of BASIC Language at that time, knew nothing about Access Basic (MS-Access Ver.2 language, a primitive form of Visual Basic).


I struggled with the problem for a while and finally decided to have a look in the Northwind.mdb sample database for clues. There it was, on the Customer Phone List Form, the technique that I was struggling for so long. Within an Option Group Control, 27 Buttons with Labels A-Z, All to filter Records of Company Name starting with the respective letter on the Button or to remove the filter using the All labeled button. The Option Group is linked to a Macro (Customer Phone List) for testing, which button on the option group is clicked, and to filter the Company Names starting with that letter. There were no second thoughts on this and I straight away transplanted this method on my first MS-Access Project. It was developed without touching a single line of Access Basic Code, all automated procedures are run with macros and this is still in use.


We will look into the Finding or Filtering records using three different methods on the same Form. You can use any one of the three methods or all of them in your Project. We will use the Products Table from the Northwind.mdb sample Database.


  1. Import the Products Table from the Northwind.mdb Database. Visit the Page Saving Data on forms not in Table to find the location reference of the Northwind.mdb database, if you are not sure where to find it.

  2. Click on the Table and select Form from Insert menu and select Autoform: Columnar from the displayed list, click OK to create the Form and save it with the suggested name: Products.


  3. Find/Filter Form image

  4. Display the Form Header/Footer Sections, if not already visible. Select Form Header/Footer from View Menu.

  5. Create a Label on the Header Section of the Form and type Products List as Caption. Click on the Label and change the character size to 20 or more, to your liking, and make it Bold using the Format Toolbar above.



  6. NB: If you would like to create the same 3D Style Heading, visit the Page: Shadow 3D Heading Style and follow the procedure explained there.


  7. Create a Command Button at the Footer Section of the Form. Display the Property Sheet of the Button (Alt+Enter or select Properties from View Menu). Change the Property Values as shown:


    • Name = cmdExit

    • Caption = Exit


  8. Design a Text Box and four Command Buttons on the Form, as shown in the shaded area of the Form. Change the property values of the Text Box and Buttons as given below:


  9. Click on the Text Box, Display the Property Sheet and change the property values:

    • Name = xFind

    • Back Color = 0



    • Text Box child Label Caption = Find / Filter Product Name


  10. Click on the first button, Display the Property Sheet and change the property Values.


    • Name = FindPID

    • Caption = << Product ID

    • Fore Color = 128


  11. Click on the second button, Display the Property Sheet and change the property Values.


    • Name = FindFirstLetter

    • Caption = << First Letter

    • Fore Color = 128


  12. Click on the third Button, Display the Property Sheet and change the property Values.


    • Name = PatternMatch

    • Caption = << Pattern Match

    • Fore Color = 128


  13. Click on the fourth Button, Display the Property Sheet and change the property Values.


    • Name = cmdReset

    • Caption = Reset Filter


  14. Display the Visual Basic Module of the form, select Tools - > Macros - > Visual Basic Editor when the Products Form is still in Design View.


  15. Copy and paste the following Code into the VB Module of the Form and save the Form:




Private Sub cmdExit_Click()
DoCmd.Close
End Sub

Private Sub cmdReset_Click()
'Remove Filter effect
'Clear Text Box
Me!xFind = Null
Me.FilterOn = False
End Sub


Private Sub FindPID_Click()
'Find Record matching Product ID
Dim m_find, rst As Recordset

m_find = Me![xFind]
If IsNull(m_find) Then
Me.FilterOn = False
Exit Sub
End If

If Val(m_find) = 0 Then
MsgBox "Give Product ID Number..!"
Exit Sub
End If

If Val(m_find) > 0 Then
Set rst = Me.RecordsetClone
rst.FindFirst "ProductID = " & m_find
If Not rst.NoMatch Then
Me.Bookmark = rst.Bookmark
End If
rst.Close
End If

End Sub


Private Sub FindfirstLetter_Click()
'Filter Names matching First character
Dim xfirstletter

xfirstletter = Me![xFind]
If IsNull(xfirstletter) Then
Me.FilterOn = False
Exit Sub
End If
If Val(xfirstletter) > 0 Then
Exit Sub
End If

xfirstletter = Left(xfirstletter, 1)
Me.FilterOn = False
Me.Filter = "Products.ProductName Like '" & xfirstletter & "*'"
Me.FilterOn = True

End Sub


Private Sub PatternMatch_Click()
'Filter Names matching the group of characters
'anywhere within the Name
Dim xpatternmatch

xpatternmatch = Me![xFind]
If IsNull(xpatternmatch) Then
Me.FilterOn = False
Exit Sub
End If

Me.FilterOn = False
Me.Filter = "Products.ProductName Like '*" & xpatternmatch & "*'"
Me.FilterOn = True
End Sub



  1. Usage of << Product ID Button.


    • Click the Button with a Number less than or equal to the Product Code range of values in the Text Box.

    • If clicked with Text Value it will ask for Product ID Number.

    • If clicked when the Text Box is empty, it is same as clicking Filter Reset Button.


  2. Usage of << First Letter Button.


    • Click the Button with any Alphabet A to Z or a to z in the Text Box.

    • If more than one character is entered only the first character will be taken.

    • If Numeric Value is entered the filter action will be ignored.

    • If clicked when the Text Box is empty, it is same as clicking the Filter Reset Button.


  3. Usage of << Pattern Match Button.


    • Click the Button with group of characters that to match anywhere within the Product Name.

    • If clicked when the text box is empty, it is same as clicking the Filter Reset Button.


  4. Usage of Filter Reset Button.


    • Resets the earlier applied Filter action.

    • Empties the Text Box Control.




Useful Report Functions
Reminder Pop Up
MS-Access & Graph Charts-2
MS-Access & Graph Charts
Reports Page Border

Labels:

4 Comments:

Blogger Sejuty said…

it doesnt work

August 28, 2008 2:32 PM  
Blogger a.p.r. pillai said…

The Example and Code is fully tested. Be specific on your issues perhaps I could help to sort it out.

If you need a demo version of the example give your e-mail address.

Regards,

August 31, 2008 4:36 PM  
Blogger Elaine said…

I'm trying to adapt this code to an excel form. the Debugger says me.filter.on is not defined. I am only using the pattern match button. Is there a difference in the tags in excel? Any idea what I need to do to define me.filter?

I can send a sample file if that would help.

March 21, 2009 1:20 AM  
Blogger a.p.r. pillai said…

The Syntax of Advanced Filter in Excel is like the sample code below:

Range("A1:J78").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("L1:L2"), Unique:=False


Range("A1:J78") is the database Range. Range("L1:L2") is the Criteria Range and Cell L1 will have the Field Name to look for data and L2 is the actual data to look for Like:

CategoryID
3

Forward a copy of the Excel file to aprpillai@msaccesstips.com.

Regards,

March 23, 2009 10:33 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