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!