DBL
Registered User.
- Local time
- Today, 23:13
- Joined
- Feb 20, 2002
- Messages
- 659
I have a search form that has 14 unbound field. As little or as many of these fields can be selected from to widen or narrow the search criteria. I have 6 text box fields that the user can enter a search term, one word in each box, which searches a certain field in the database.
I've been using the where statement to string together the variables and search a query for the results before exporting to Excel:
If Not IsNull(Me.Combo6) Then
where = where & " AND [AuthName] = '" + Me![Combo6].Column(1) & "'"
End If
If Not IsNull(Me.Combo31) Then
where = where & " AND [DCategory] = '" + Me![Combo31].Column(1) & "'"
End If
If Not IsNull(Me.Combo33) Then
where = where & " AND [Path1] = '" + Me![Combo33].Column(1) & "'"
End If
If Not IsNull(Me!Text35) Then
where = where & " AND [PMPlace1] like '" + "*" + Me![Text35] + "*" + "'"
End If
If Not IsNull(Me!Text8) Then
where = where & " AND [cdcause] like '" + "*" + Me![Text8] + "*" + "'"
End If
This works well until I try and bring in any of the text fields (text 8 is the first one) If I try and run the query with a second item in the second text field [text10] then the query shows the first critera row correctly but the second text field item is in an Or criteria row on it's own - so it gives me records without the other criteria in place.
I've tried using:
If Not IsNull(Me![Text10]) Then
where = where & " or[PMDate] Between " + F + " And " + T _
& " and[AuthName] = '" + Me![Combo6].Column(1) & "'" + "" _
& " and [Path1] = '" + Me![Combo33].Column(1) & "'" + "" _
& " and [DCategory] = '" + Me!Combo31.Column(1) & "'" + "" _
& " and [PMPlace1] Like '" + "*" + Me![Text35] + "*" + "'" _
& " and [CDCause] Like '" + "*" + Me![Text10] + "*" + "'"
as the search string for the Or row in the query which works but only if you select a search criteria for the other fields too. If you leave one of those blank I just get a syntax error.
Is there a better way of pulling these variables out into a query?
I've been using the where statement to string together the variables and search a query for the results before exporting to Excel:
If Not IsNull(Me.Combo6) Then
where = where & " AND [AuthName] = '" + Me![Combo6].Column(1) & "'"
End If
If Not IsNull(Me.Combo31) Then
where = where & " AND [DCategory] = '" + Me![Combo31].Column(1) & "'"
End If
If Not IsNull(Me.Combo33) Then
where = where & " AND [Path1] = '" + Me![Combo33].Column(1) & "'"
End If
If Not IsNull(Me!Text35) Then
where = where & " AND [PMPlace1] like '" + "*" + Me![Text35] + "*" + "'"
End If
If Not IsNull(Me!Text8) Then
where = where & " AND [cdcause] like '" + "*" + Me![Text8] + "*" + "'"
End If
This works well until I try and bring in any of the text fields (text 8 is the first one) If I try and run the query with a second item in the second text field [text10] then the query shows the first critera row correctly but the second text field item is in an Or criteria row on it's own - so it gives me records without the other criteria in place.
I've tried using:
If Not IsNull(Me![Text10]) Then
where = where & " or[PMDate] Between " + F + " And " + T _
& " and[AuthName] = '" + Me![Combo6].Column(1) & "'" + "" _
& " and [Path1] = '" + Me![Combo33].Column(1) & "'" + "" _
& " and [DCategory] = '" + Me!Combo31.Column(1) & "'" + "" _
& " and [PMPlace1] Like '" + "*" + Me![Text35] + "*" + "'" _
& " and [CDCause] Like '" + "*" + Me![Text10] + "*" + "'"
as the search string for the Or row in the query which works but only if you select a search criteria for the other fields too. If you leave one of those blank I just get a syntax error.
Is there a better way of pulling these variables out into a query?