Results 1 to 2 of 2
  1. #1
    N7925Y is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2016
    Posts
    32

    Search results only brings up the first letter

    I have a form that I use to search through my contacts. It's only bringing back results based off of the first letter in the contact. Example would be if I type the letter "A" it only brings up the names that start A. Not names that have the letter A in it such as "Brad". Below is the code I am using. Any thoughts?

    Private Sub btnSearch_Click()
    If Me.txtFirstName = vbNullString Then Me.txtFirstName = "*"
    If Me.txtLastName = vbNullString Then Me.txtLastName = "*"
    If Me.cboCounty = vbNullString Then Me.cboCounty = "*"
    Dim SQL As String
    SQL = "SELECT * from Contacts where FirstName Like '" & Me.txtFirstName & " *' AND LastName Like '" & Me.txtLastName & "*' AND County Like '*" & Me.cboCounty & "'" & " ORDER By LastName"

    ' Debug.Print SQL
    Me.CountactSubform.Form.RecordSource = SQL
    Me.ContactSubform.Form.Requery


    End Sub

  2. #2
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If you substitute "A" for txtFirstName, you should see why Like '" & Me.txtFirstName will only return names beginning with A:
    Like 'A*'
    To get Brad, you'd need an asterisk before the "A"
    Like '*A*'
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 09-12-2016, 11:49 AM
  2. Replies: 3
    Last Post: 09-02-2013, 04:33 PM
  3. Replies: 4
    Last Post: 09-18-2012, 05:07 AM
  4. Replies: 2
    Last Post: 06-08-2012, 11:22 AM
  5. Query Brings back duplicate results
    By DaveyJ in forum Queries
    Replies: 1
    Last Post: 06-10-2010, 05:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums