RickDB
Registered User.
- Local time
- Today, 00:47
- Joined
- Jun 29, 2006
- Messages
- 101
I am using the attached sample to build my search form on.
I have a problem though. The sample searches multiple fields based on unbound entries on the form, but each only searches individual results from a query.
Example:
There may be an address saved to the customer table, and an address saved in the order table for that customer.
Here is the serach sample's VBA:
If Me![NewsPaper] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.NewsPaper = """ & NewsPaper & """"
End If
will only search the 'NewsPaper' field in the qrySearchCriteriaSub query. What if there was a second field in the query 'Newspaper2' (as a generic example). How can I alter this VBA to search both 'NewsPaper' and 'NewsPaper2' based on what is entered into [NewsPaper] on the search form?
Am I looking at this right? Or should I be asking myself how to concatenate the 'NewsPaper' & 'Newspaper2' fields into one query result that can then be searched?
Thanks in advance for your responses!
I have a problem though. The sample searches multiple fields based on unbound entries on the form, but each only searches individual results from a query.
Example:
There may be an address saved to the customer table, and an address saved in the order table for that customer.
Here is the serach sample's VBA:
Private Sub cmdSearch_Click()
On Error Resume Next
Dim sSql As String
Dim sCriteria As String
sCriteria = "WHERE 1=1 "
'tblSubject qrySearchCriteriaSub
If Me![Index] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.Index = """ & Index & """"
End If
If Me![Title] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.Title like """ & Title & "*"""
End If
If Me![AreaCode] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.AreaCode = """ & AreaCode & """"
End If
If Me![NewsPaper] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.NewsPaper = """ & NewsPaper & """"
End If
If Me![StartDate] <> "" And EndDate <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.DateOfPaper between #" & Format(StartDate, "dd-mmm-yyyy") & "# and #" & Format(EndDate, "dd-mmm-yyyy") & "#"
End If
If Me![Subject] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.Subject like """ & Subject & "*"""
End If
sSql = "SELECT DISTINCT [NewsPaperID], [Index],[Title],[AreaCode],[NewsPaper],[DateofPaper],[Subject] from qrySearchCriteriaSub " & sCriteria
Forms![frmSearchCriteriaMain]![frmSearchCriteriaSub].Form.RecordSource = sSql
Forms![frmSearchCriteriaMain]![frmSearchCriteriaSub].Form.Requery
',[Title],[AreaCode],[NewsPaper],[StartDate],[EndDate],[Subject]
'frmSearchCriteriaSub.Requery
End Sub
If Me![NewsPaper] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.NewsPaper = """ & NewsPaper & """"
End If
will only search the 'NewsPaper' field in the qrySearchCriteriaSub query. What if there was a second field in the query 'Newspaper2' (as a generic example). How can I alter this VBA to search both 'NewsPaper' and 'NewsPaper2' based on what is entered into [NewsPaper] on the search form?
Am I looking at this right? Or should I be asking myself how to concatenate the 'NewsPaper' & 'Newspaper2' fields into one query result that can then be searched?
Thanks in advance for your responses!