Thank you for all your help. but the code that you gave me is still not working (probably I'm missing something) Here is what I did: On the query (that showed all the data on the subform) on the partID criteria:
- Like "*" & [forms]![frmsearch]![txtid] & "*" or Like "*" & [forms]![frmsearch]![txtid] & "*"
-
and on the description criteria, I put: Like "*" & [forms]![frmsearch]![txtdesc] & "*" or Like "*" & [forms]![frmsearch]![txtdesc] & "*"
but I don't really know where I should put the code (part 3 and part 4). Is it on the search button? because my search button code is DoCmd.Requery "search subform"
Make sure the the criteria is entered on seperate lines (if on the same line as each other AND is implied. if on different rows then OR is implied)
Switch to SQL View, copy and paste your query for us to see pls.
The SELECT portion should be similar to
The WHERE portion should look similar to below.
- WHERE partid Like "*" & [forms]![frmsearch]![txtid] & "*"
-
OR description Like "*" & [forms]![frmsearch]![txtdesc] & "*"
As previously posted you will have to learn to handle Null or no entries.
This gets a little more complicated if your users have multiple fields to choose from. 99% of the time a user knows a partial partnbr or partial part description and would want to search by one or the other.
The complication is on you, the developer. You may need to set the datasource of the form via code using SQL statements now. You need to decide if you want to give the user the
option to search by multiple fields or only one at a time.
Insert an "Option Group" in your search form. Option 1 could be show all number. Option 2 could be part number. Option 3 could be part description, etc. You could have a lot of options. Give the "Option Group" control a good name - opt1 - Access calls it Frame0 if the first frame or option group.
You only need one Textbox for search criteria - i called it txtSearch.
Within the Code for the search button:
-
Dim strSQL as String
-
Dim strCrit as String
-
Dim iNull as integer
-
-
strSQL = "Select * From tblParts"
-
-
If Me.opt1 > 1 Then
-
If isnull(Me.txtSearch)
-
Msgbox "You must enter search ctriteria!"
-
Me.txtSearch.Setfocus
-
Exit Sub
-
End If
-
End If
-
-
Select Case Me.opt1
-
Case 1
-
strCrit = ";"
-
Case 2
-
strCrit = " WHERE partid Like "*" & [forms]![frmsearch]![txtSearch] & "*" & ";"
-
Case 3
-
strCrit = " WHERE description Like "*" & [forms]![frmsearch]![txtSearch] & "*" & ";"
-
End Select
-
-
Me.RecordSource = strSQL & strCrit
-
-
Don't let us make this seem impossible with all of the code and SQL geek speak. :D