Results 1 to 3 of 3
  1. #1
    bellczar is offline Novice
    Windows 8 Access 2007
    Join Date
    Feb 2013
    Posts
    9

    Using a search box within an Access form

    I have added a search box to the header of an Access form starting with code I found in an article by Susan Harkins on TechRepublic.com. http://www.techrepublic.com/blog/mso...cess-form/2102



    The search works, with problems. The code is below. (My text box is Text59, my table is called songs, and the search field is called title.)

    Here are the problems:

    1) I have to enter my search string in the search box with quotation marks, e.g. "God Bless America". How can I fix this so I don't need the quotation marks?

    2) I would like to search by substring. I would like the search to retrieve the first matching record alphabetically. So if I am searching for "God Bless America" it might be all I have to type is "God Bless A" and it will go to the correct record. If I am not getting ahead of myself, could this mean it would search by a substring that is the length of the search string I entered? So some function like len(Text59) would return a value of that length (in this example 11) and then search the table with a substring of len?

    Thanks. Tony


    Private Sub Text59_AfterUpdate()
    'Find record based on contents of Text59.

    Dim strSearch As String

    On Error GoTo errHandler

    'Delimited for text search.

    'strSearch = "songs.title = " & Chr(39) & Me!Text59.Value & Chr(39)

    'Delimited for numeric values.

    strSearch = "songs.title = " & Me!Text59.Value

    'Find the record.

    Me.RecordsetClone.FindFirst strSearch

    Me.Bookmark = Me.RecordsetClone.Bookmark

    Exit Sub

    errHandler:

    MsgBox "Error No: " & Err.Number & "; Description: " & _
    Err.Description

    End Sub

  2. #2
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    strSearch = "songs.title = " & Me!Text59.Value
    change this to..


    strSearch = "song.title Like '*" & me!Text59 & "*'"

    no quotes and it will return all values with that text in it.

  3. #3
    bellczar is offline Novice
    Windows 8 Access 2007
    Join Date
    Feb 2013
    Posts
    9
    Thanks for your help.

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

Similar Threads

  1. Creating a search form in access
    By fawadmz in forum Access
    Replies: 2
    Last Post: 10-15-2012, 12:48 AM
  2. Creating a search box in Access 2010 form
    By d4jones in forum Forms
    Replies: 3
    Last Post: 07-18-2012, 02:53 PM
  3. Replies: 5
    Last Post: 07-13-2012, 01:15 AM
  4. Creating an Access Search Form
    By Icky_Joe in forum Forms
    Replies: 2
    Last Post: 08-16-2010, 11:33 AM
  5. access search open new form
    By jellybeannn in forum Access
    Replies: 1
    Last Post: 08-05-2010, 05:18 AM

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