473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Partial Search

Hi, I need help regarding partial search. Currently i have a textbox named txtSite and when i press enter, it retrieves records from the table "ServiceRec" whereby the value for "SiteAddress" = the value typed in "txtSite". It works fine but i want the user to be able to search for records even if they do not type the address in full.

Currently, my code is as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSite_Enter()
  2.  
  3. Dim strSql As String
  4.  
  5. strSql = "Select * From ServiceRec Where SiteAddress = '" & Me!txtSite & "'"   
  6. Me.ServiceRecSubform.Form.RecordSource = strSql
  7.  
  8. ServiceRecSubform.Visible = True
  9. info1Subform.Visible = False
  10.  
  11.  
  12. End Sub
How should i edit the code? Thanks
Oct 31 '08 #1
4 2791
Stewart Ross
2,545 Expert Mod 2GB
Hi Evanescent. Partial string matching is straightforward - use the Like operator and precede and follow your match string with the wildcard character, the asterisk:

Expand|Select|Wrap|Line Numbers
  1. strSql = "Select * From ServiceRec Where SiteAddress Like '*" & Me!txtSite & "*'"
-Stewart
Oct 31 '08 #2
ADezii
8,834 Expert 8TB
You may also wish to execute your code only if a value actually exists in txtSite:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSite_Enter() 
  2. Dim strSql As String 
  3.  
  4. If Not IsNull(Me![txtSite]) Then
  5.   strSql = "Select * From ServiceRec Where ServiceRec.SiteAddress " & _
  6.            "Like '*" & Me!txtSite & "*'"
  7.   Me.RecordSource = strSql
  8.   Me.ServiceRecSubform.Form.RecordSource = strSql 
  9.  
  10.   ServiceRecSubform.Visible = True 
  11.   info1Subform.Visible = False 
  12. End If
  13. End Sub
Nov 1 '08 #3
Thanks a lot for the reply. It works =)
Nov 1 '08 #4
missinglinq
3,532 Expert 2GB
I've got to ask ***how*** this code works! I understand how the SQL statement works, but how does having the code in the

Private Sub txtSite_Enter()

event work?

This event fires when the user tabs into the txtSite textbox, not when the <Enter> key is pressed! You'd have to enter your search string, exit the textbox, then re-enter the textbox to trigger the code.

Linq ;0)>
Nov 1 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ArunPrakash | last post by:
Hi All, I have the following scenario. I have a table called Invoice. This has around 30 columns of which i have to do a retrieval based on filter conditions on 10 columns. These filters need to...
21
by: nospam | last post by:
Ok, I asked this question before and I also looked at the book "First Look at ASP.NET 2.0" I also read Paul wilson's web page explanation. HOWEVER...... The book and that web page talks about...
2
by: Larry | last post by:
I have the following code attached to a search button on a form that runs a query. It works great, except that the search for Last Name only returns exact matches. It is even case sensitive....
1
by: Liu, Mingyi | last post by:
Sorry if this question has been asked before. I tried to search in postgres mailing lists at http://archives.postgresql.org/pgsql-general/ just now and it gave me error "An error occured! Can not...
1
by: Bruce One | last post by:
I generate some classes and put inside a DLL. I have others classes outside the DLL. I have a problem that the classes outside the DLL are partial classess of the other classes inside the DLL....
0
by: mplands | last post by:
I have an access database that has two main elements; -Client Detail -Properties To expalin my problem as sussinctly as possible may be difficult but here i go... I have created a form called...
2
by: Dica | last post by:
i've converted a 1.1 dot net app to 2.0 which has split all my classes into partials. when i try to build the app, i keep getting an error about "The type 'myClassName.bookingApproval' already...
3
by: gyap88 | last post by:
I m currently creating a search engine for my database using visual basic 2005. I want to my program to return search result even if the user only enter PARTIAL matches. Dim city As String...
1
by: chungiemo | last post by:
Hi thought I would do another thread as this one is a bit different from the previous problem I am looking for a solution to the relating problem Comparing 2 access databases with 2 tables,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.