Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Field for Subform

Status
Not open for further replies.

perrymans

IS-IT--Management
Nov 27, 2001
1,340
US
I have a subform to enter details. The user selects an item from a combo box, then enters the value.

How can I create a search, from the main form, that will filter the main form, but is searching the subform info?

Example: I have a form with all computers. The subform contains IP Addresses. I want to search for all computers with IP addresses of 192.168.1.*

Thanks. Sean.
 
I got it! I did a Google search and found some pretty hard examples. Fortuantely, I found an easy one:

Code:
Private Sub cmdSubSearch_Click()
Dim strSQL As String
Dim strSearch As String
If IsNull(Me.txtSubSearch) Then
    ' If the combo is Null, use the whole table as the RecordSource.
    Me.RecordSource = "SelQ_Item"
Else
    strSearch = Me.txtSubSearch
    strSQL = "SELECT DISTINCTROW SelQ_Item.* FROM SelQ_Item " & _
        "INNER JOIN SelQ_ItemDetail ON " & _
        "SelQ_Item.ItemID = SelQ_ItemDetail.ItemID " & _
        "WHERE (((SelQ_ItemDetail.ItemDetailValue) Like '*" & strSearch & "*'));"
    Me.RecordSource = strSQL
End If
End Sub

Just uses an Inner Join. The remove filter button just resets the recordsource back to the original query.

Thanks. Sean.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top