A
angogwanon
I am trying to setup a Search Button with four possible variables. The
results need to show all records containing the variables entered.
I have four different tables in my database and a main form that allows the
person to add new records or search the four queries. The person selects the
query the wish to search, then types in the search information. I made sure
the names of the search fields are the same in all four queries (company,
web, city, and state). The state field is a combo box.
I am able to set up the code to get the WHERE part of the query filter.
However, I am unable to figure out how to execute the query with the WHERE
filter. Below is the code I have so far:
Dim strWhere As String
Dim strQuery As String
If Me.Sourcequery.Value >= 1 Then
strQuery = Me.Sourcequery.Value
'Filtering each text box for values
If Not IsNull(Me.txtCompName) Then
strWhere = strWhere & "([Company] like ""*" & Me.txtCompName &
"*"")"
End If
If Not IsNull(Me.txtWeb) Then
strWhere = strWhere & "([Web] like ""*" & Me.txtWeb & "*"")"
End If
If Not IsNull(Me.txtCity) Then
strWhere = strWhere & "([City] like ""*" & Me.txtCity & "*"")"
End If
If Not IsNull(Me.cboState) Then
strWhere = strWhere & "([State]= """ & Me.cboState & """)"
End If
What is the code to open the query with the completed strWhere as the
filter? I appreciate any help I can get. If there is another way, please
let me know. While I have used VB in the past, it has been awhile.
results need to show all records containing the variables entered.
I have four different tables in my database and a main form that allows the
person to add new records or search the four queries. The person selects the
query the wish to search, then types in the search information. I made sure
the names of the search fields are the same in all four queries (company,
web, city, and state). The state field is a combo box.
I am able to set up the code to get the WHERE part of the query filter.
However, I am unable to figure out how to execute the query with the WHERE
filter. Below is the code I have so far:
Dim strWhere As String
Dim strQuery As String
If Me.Sourcequery.Value >= 1 Then
strQuery = Me.Sourcequery.Value
'Filtering each text box for values
If Not IsNull(Me.txtCompName) Then
strWhere = strWhere & "([Company] like ""*" & Me.txtCompName &
"*"")"
End If
If Not IsNull(Me.txtWeb) Then
strWhere = strWhere & "([Web] like ""*" & Me.txtWeb & "*"")"
End If
If Not IsNull(Me.txtCity) Then
strWhere = strWhere & "([City] like ""*" & Me.txtCity & "*"")"
End If
If Not IsNull(Me.cboState) Then
strWhere = strWhere & "([State]= """ & Me.cboState & """)"
End If
What is the code to open the query with the completed strWhere as the
filter? I appreciate any help I can get. If there is another way, please
let me know. While I have used VB in the past, it has been awhile.