Solved

How do I create a "Type to Query" form in Access?

Posted on 2011-02-11
6
196 Views
Last Modified: 2012-05-11
I have a database with a large number of contacts.  I would like to create a form where I could easily narrow down my results by typing.  

Example:  

My form has 2 text fields.  fld_fname and fld_lname.  There is a list box showing all my contacts.  

I would like to narrow down the list by typing criteria in the fields.  Putting an A in fld_fname and T in fld_lname would narrow down the list to only show contacts with the initials A T etc...

Any thoughts?  

Oh yeah, I'm using Access 2003.  
0
Comment
Question by:NDawg
  • 3
  • 2
6 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 300 total points
ID: 34869774
You can use the Filter property of the Form. Add a couple of textboxes to your form (one to filter by fld_fname, another to filter by fld_lname) and then do this in the AFterUPdate event of both:

Me.Filter = "fld_lname LIKE '" & me.txtYourLNameSearchBox & "*'"
Me.FilterOn = True

You could also use the Change event of those boxes, and reference the Text property:

Me.Filter = "fld_lname LIKE '" & me.txtYourLNameSearchBox.Text & "*'"
Me.FilterOn = True

Note that .Text works ONLY when that box has the focus.
0
 

Author Comment

by:NDawg
ID: 34869894
Hey LSM, Thanks for the quick response.  Both work, but for my needs I'm going with the Chane event.  

Just did a quick test and the code works, but only allows for 1 character at a time.  As soon as I type the second letter it replaces the first letter.  

I've gotta sign off for now, but will continue to dig more tomorrow.  
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 200 total points
ID: 34870777
you will need a string variable holder

private sub text0_change()
dim str as string
str=str & me.text0.text

me.filter="[fldName] like '" & str & "*'"
me.filteron=true
end sub
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:NDawg
ID: 34877091
Ok. I think I've figure out what the problem is.  After filtering, the field is coming back with the entire contents selected.  That is why the second letter is replacing the first letter instead of being appended to it.  
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34878359
the text box where you are typing the information must be UNBOUND for this to work.
0
 

Author Closing Comment

by:NDawg
ID: 34908383
Both suggestions were a big help at getting me pointed in the right direction, but neither was a perfect solution.  I would give an A- if I could, but I can't.  

I'm old school access guy from way back.  As I got in to linux I eventually stopped spending much time with it.  I've got a project that calls for it and have found a few things have changed and that I've forgotten a few things.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now