Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Which event runs as i type in a control
Mubeezi Micah 

15 years ago
Dear Richard,

Finally…I got the answer to my question just by keenly following the flow of Access events. The searches in my Access database are now “live” i.e., as I type (letter by letter) in a control, the search automatically begins and the closest matches populate in a listbox. I will share this quick code with my fellow students who might also find it useful.
NB: In this example, I search for the names of my TB patients. On my Search form, there is a textbox named PtNameSearch. In a table named PtDetailsT, there is a field named PtName. Additionally, NameSearchList is the name of the listbox where the closest matches are populated.
Please read additional explanations in the code. In case you are interested in a more challenging way to handle this, please visit http://allenbrowne.com/AppFindAsUType.html

Private Sub PtNameSearch_Change()

    Dim W As String
    Dim S As String
    W = ""
    S = ""
    
    
    Me.Refresh 'As you type in a textbox, it becomes "Dirty". This part of code forces Access to save every letter typed (no longer dirty). After saving the word/letter typed, the Me.refresh code highlights all the text inside the control that the user is typing in. Without the next line of code, when the user types the next letter, the previous letter is deleted/overtyped

    Me!PtNameSearch.SelStart = Me!PtNameSearch.SelLength 'This wonder line of code forces the cursor to move to the infront of the last letter that the user has typed. See details of the original authour here http://www.mvps.org/access/forms/frm0011.htm

    W = " PtName LIKE ""*" & PtNameSearch & "*"" " 'Now that the letter/text has been saved, the search can begin!
      
    
    S = " SELECT PatientID, TBMgtUnitNo, RegDate, PtName, Sex, Age, County, Payam, Boma, Village, TbType, PtType, PtCategory FROM PtDetailsT "
    
    If W <> "" Then
    S = S & " WHERE " & W
    End If
    
    NameSearchList.RowSource = S

End sub

I will be happy to provide more explanations to anyone if necessary

Best regards,

MICAH


Reply from Richard Rost:

Thanks for sharing!

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/9/2026 9:23:46 AM. PLT: 0s