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 
Search as you type spaces
Stephen Fugowski 
    
2 years ago
I have no problems with search boxes until I hit the space bar in the search field. How can I solve this problem?
Kevin Robertson  @Reply  
          
2 years ago
The Access Search Seminar covers this.
Stephen Fugowski OP  @Reply  
    
2 years ago
That would be great if I had $230. I'm on a fixed income (Social Security only) and can't afford any seminars.
Sami Shamma  @Reply  
             
2 years ago
Stephen,

please give more details of the problem you are having, and we will try to help you.
Alex Hedley  @Reply  
           
2 years ago
Jeffrey Kraft  @Reply  
      
2 years ago
On the search box set up a on Keypress Event.  KeyAscii = 32 is the space key

Private Sub MySearch_KeyPress(KeyAscii As Integer)
    If KeyAscii = 32 Then
        blnspace = True
    Else
        blnspace = False
    End If
End Sub

And then using the Search Form 2.0 change() event or however you did yours.
Jeffrey Kraft  @Reply  
      
2 years ago

Jeffrey Kraft  @Reply  
      
2 years ago
Or maybe you could use a wildcard * when you intend to use a space?
Stephen Fugowski OP  @Reply  
    
2 years ago
Thank you all.  I tried using Jeffrey's suggestion, and itdid put a space when I checked for KeyAscii - 32, but it put a space before what was in the Search Text box. Here is the code I used:

Private Sub SearchBoxAddr_KeyPress(KeyAscii As Integer)

    If KeyAscii = 32 Then
        Me.SearchBoxAddr.SetFocus
        Me.SearchBoxAddr.Sel = Len(SearchBoxAddr.Text)
        Me.SearchBoxAddr.Text = Me.SearchBoxAddr.Text & " "
        
    End If

End Sub
Lars Schindler  @Reply  
     
2 years ago
Private Sub SearchBoxAddr_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = 32 Then  ' Check if the Space key was pressed
        ' Prevent the default handling of the space key
        KeyCode = 0
        
        ' Manually add the space to the text box value
        Me.SearchBoxAddr.Value = Me.SearchBoxAddr.Value & " "
        
        ' Set the cursor to the end of the text
        Me.SearchBoxAddr.SelStart = Len(Me.SearchBoxAddr.Value)
    End If

End Sub
Stephen Fugowski OP  @Reply  
    
2 years ago
Well, thank you Lars. It Finally worked, but with one change in your code: I changed "KeyCode" to "KeyAscii". Once again, thank all of you who helped.
Lars Schindler  @Reply  
     
2 years ago
Great that it worked out.
You had probably used KeyPress and not KeyDown and therefore needed KeyAscii.

Incidentally, the code was not my idea either, but the result I was able to achieve with ChatGPT after ChatGPT had first tried quite a lot of nonsense until I gave it the right link, which ChatGPT was then able to enlighten after all:
https://599cd.com/blog/display-article.asp?ID=2777

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/30/2026 3:36:00 AM. PLT: 1s