Results 1 to 5 of 5
  1. #1
    lisanoe is offline Novice
    Windows 8 Access 2007
    Join Date
    Jan 2015
    Posts
    8

    Search Button with Text Box won't work


    Hello,

    I have a form that I need to search on last name to find the person I need edit. THe code I am using brings back the 3077 error code for missing syntax. Please review and let me know what is wrong with the code. Would also like to add a button to add new data, I know I can do that at the bottom but I still would like a button.

    Code:
    Private Sub Search_Click()
         Dim bkmk As Variant
         Dim strField As String    Me.RecordsetClone.MoveFirst
        Me.RecordsetClone.FindFirst "LAST NAME Like" _
        & Chr(34) & Me.SearchText & "*" & Chr(34)
         
         If Me.RecordsetClone.NoMatch Then
             MsgBox "No Match"
         Else
             bkmk = Me.RecordsetClone.Bookmark
             Me.Recordset.Bookmark = bkmk
         End If
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    just use a filter

    Code:
    Private Sub Search_Click()
       me.filter = "[lastName] like '*" & txtSearch & "*'"
       me.filterOn = true
    end sub

  3. #3
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Filter is a good suggestion, but just so you learn from your experience, I think it's the way you wrote the criteria expression that is the problem.
    Your code likely results in a string that looks like
    Last NameLike"textvaluehere*" (no spaces at all)
    instead of
    Last Name Like "textvaluehere*"
    When possible, I also prefer the nested single quotes like ranman256 used over the character codes you used.
    Last edited by Micron; 12-16-2015 at 06:41 PM. Reason: grammar edit

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Advise no spaces or special characters/punctuation (underscore is exception) in naming convention. Space in field name may also be causing an issue. If used enclose in [] as shown by ranman.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Am I getting too old for this? How did I miss that? [ ]

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

Similar Threads

  1. How does your search work?
    By Dorothy in forum Forum Suggestions
    Replies: 5
    Last Post: 08-21-2019, 07:02 AM
  2. Replies: 2
    Last Post: 03-12-2014, 01:31 AM
  3. Replies: 5
    Last Post: 07-13-2012, 01:15 AM
  4. Replies: 12
    Last Post: 03-22-2012, 02:48 AM
  5. Replies: 1
    Last Post: 03-19-2012, 11:03 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