Solved

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

Posted on 2011-02-11
6
197 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 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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