Results 1 to 4 of 4
  1. #1
    Aeonem is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    8

    Question Search bar using bound form

    Hello,
    I've been trying to create a search bar in a form that will find a record within a table when clicking on a button. Then it will populate several text boxes with values from several fields in the table. However keep running into a data type mismatch in criteria expression problems. (Error '3464').

    I would rather have a search bar feature than a combo box drop down list to search which I'm currently using.

    Names of things:
    Button = cmdSearchBar


    Search text box = txtSearch (Unbound; not sure if it needs to be bound to anything)
    Table = tblProducts
    The field that the search bar is looking in is called "Item".

    The text boxes that I want to be populated and the fields they should come from (All text boxes are bound to the table):
    Text box : Field
    txtStockSearch : "Stock"
    txtMinStockSearch : "Min Stock Level"
    txtItemSearch : "Item"
    txtBuyingPriceSearch : "Buying Price"
    txtSupplierSearch : "Supplier"

    I'm currently using the code:
    Private Sub cmdSearchBar_Click()
    If IsNull(txtSearch) = False Then
    Me.Recordset.FindFirst "[Item]=" & txtSearch
    Me!txtSearch = Null
    If Me.Recordset.NoMatch Then
    MsgBox "No Item found", vbOKOnly + vbInformation, "Sorry"
    Me!txtSearch = Null
    End If
    End If
    End Sub

    The debugger says this line of code is incorrect:
    Me.Recordset.FindFirst "[Item]=" & txtSearch

    I believe that it could have something to do with the "[Item]=" (The field name). However I don't have a lot of experience with VBA.

    Any help would be appreciated,
    Thanks!

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    "[Item]=" & txtSearch

    is the correct syntax if [Item] is defined as a Numbers Datatype. I suspect that it is defined as Text, in which case the correct syntax would be

    "[Item]='" & txtSearch & "'"

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Aeonem is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    8
    Thank you Linq

    Works perfectly now!

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    BTW, Welcome to AFN!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 6
    Last Post: 01-30-2014, 05:57 PM
  2. Can a form be bound to more than one table?
    By Access_Novice in forum Forms
    Replies: 4
    Last Post: 10-24-2013, 06:23 PM
  3. Replies: 3
    Last Post: 07-24-2012, 03:11 PM
  4. Bound form with bound combobox
    By Jerry8989 in forum Access
    Replies: 2
    Last Post: 12-05-2011, 01:50 PM
  5. Replies: 0
    Last Post: 05-09-2010, 08:43 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