JustPunkin
Registered User.
- Local time
- Today, 03:44
- Joined
- Jan 8, 2009
- Messages
- 38
OK, I have made some good progress on this program, but I've found a flaw in my thinking.
I'm using a SQL string to call a query. In that SQL string, I'm using a lot of If/Then statements. It's working the way I want it to work. You generally have three choices Yes, No, NA. If it's Yes, it searches for -1, if it's no, it searches for 0, if it's NA, it eliminates it from the query.
This works great, until I get to a search criteria that is not Yes or No.
In my table, I have two fields NoDC1 and NoDC2. In my search form, I have a txtbox for Number of DC's. You can enter any number you want.
I then have this in my SQL:
It gives me the desired results. If there is a number there, it searches the two fields and returns the results that have the number in either field.
The problem arises when I add another criteria to the mix. Because it's written as an AND/OR statement, the SQL string returns this:
It is searching for all projects where surrogate rings = -1 and NoDC1 is 10 OR all projects where NoDC2 is 10.
What I want it to do is search for all projects where surrogate rings = -1 and NoDC1 or NoDC2 = 10.
Any advice?
I'm using a SQL string to call a query. In that SQL string, I'm using a lot of If/Then statements. It's working the way I want it to work. You generally have three choices Yes, No, NA. If it's Yes, it searches for -1, if it's no, it searches for 0, if it's NA, it eliminates it from the query.
This works great, until I get to a search criteria that is not Yes or No.
In my table, I have two fields NoDC1 and NoDC2. In my search form, I have a txtbox for Number of DC's. You can enter any number you want.
I then have this in my SQL:
Code:
If Me.txtDCNo = "" Then
strSQL = strSQL & "like '*'"
ElseIf Me.txtDCNo <> "" Then
strSQL = strSQL & "AND tblMechanicalFeatures.NoDC1 = " & Me.txtDCNo & "" & vbNewLine
strSQL = strSQL & "OR tblMechanicalFeatures.NoDC2 = " & Me.txtDCNo & "" & vbNewLine
End If
Trim (Me.txtDCNo)
It gives me the desired results. If there is a number there, it searches the two fields and returns the results that have the number in either field.
The problem arises when I add another criteria to the mix. Because it's written as an AND/OR statement, the SQL string returns this:
Code:
SELECT tblMechanicalFeatures.*, [General Project Information].*
FROM tblMechanicalFeatures INNER JOIN [General Project Information] ON tblMechanicalFeatures.KeyNumber = [General Project Information].[Key Number]
WHERE [General Project Information].[Surrogate Rings] = -1
AND tblMechanicalFeatures.NoDC1 = 10
OR tblMechanicalFeatures.NoDC2 = 10
ORDER BY tblMechanicalFeatures.KeyNumber;
It is searching for all projects where surrogate rings = -1 and NoDC1 is 10 OR all projects where NoDC2 is 10.
What I want it to do is search for all projects where surrogate rings = -1 and NoDC1 or NoDC2 = 10.
Any advice?