R
ryguy7272
Hello SQL experts! I thought my SQL was working, but it actually only works
when I click the ‘And’ radio button. Here is my design: DateFrom (ComboBox)
and DateTo (ComboBox); Customer (ListBox) and Trader (ListBox); finally ‘And’
(RadioButton) and ‘Or’ (RadioButton). If I click the ‘And’ button, the query
works fine FOR THE DATES. If I click the ‘Or’ button, I get only matching
records from Customer and Trader, BUT I GET ALL DATES.
I have some VBA that captures all the values and strings on my Form, passes
all to the stuff to a final string where I create this query:
' Build SQL statement
strSQL = "SELECT * FROM Trades " & _
"WHERE Trades.[TDATE] Between [Forms]![QueryForm]![cboFrom] And
[Forms]![QueryForm]![cboTo] And Trades.[Cust] " & strCust & _
strTraderCondition & "Trades.[Trader] " & strTrader & ";"
Actual SQL is here:
SELECT *
FROM Trades
WHERE Trades.[TDATE] Between [Forms]![QueryForm]![cboFrom] And
[Forms]![QueryForm]![cboTo] And Trades.[Cust] Like '*' AND Trades.[Trader]
Like '*';
I think it may be a matter of adding parentheses, to get the order of
operations right, but I’m not sure. I can post all VBA code if that helps,
but I’m not sure its necessary and my just be more confusing.
Any thoughts on this?
Thanks!
Ryan---
when I click the ‘And’ radio button. Here is my design: DateFrom (ComboBox)
and DateTo (ComboBox); Customer (ListBox) and Trader (ListBox); finally ‘And’
(RadioButton) and ‘Or’ (RadioButton). If I click the ‘And’ button, the query
works fine FOR THE DATES. If I click the ‘Or’ button, I get only matching
records from Customer and Trader, BUT I GET ALL DATES.
I have some VBA that captures all the values and strings on my Form, passes
all to the stuff to a final string where I create this query:
' Build SQL statement
strSQL = "SELECT * FROM Trades " & _
"WHERE Trades.[TDATE] Between [Forms]![QueryForm]![cboFrom] And
[Forms]![QueryForm]![cboTo] And Trades.[Cust] " & strCust & _
strTraderCondition & "Trades.[Trader] " & strTrader & ";"
Actual SQL is here:
SELECT *
FROM Trades
WHERE Trades.[TDATE] Between [Forms]![QueryForm]![cboFrom] And
[Forms]![QueryForm]![cboTo] And Trades.[Cust] Like '*' AND Trades.[Trader]
Like '*';
I think it may be a matter of adding parentheses, to get the order of
operations right, but I’m not sure. I can post all VBA code if that helps,
but I’m not sure its necessary and my just be more confusing.
Any thoughts on this?
Thanks!
Ryan---