Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-11
6
Medium Priority
?
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 900 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 600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

730 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