Hi D
I use the following code to generate the query.
Sub SQLStatement()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL
strSQL = "SELECT CCandBank.ProcessedDate, " & _
"CCandBank.CardUser, " & _
"CCandBank.TransactionDetails, " & _
"CCandBank.Amount, " & _
"CCandBank.SortCode "
strSQL = strSQL & " FROM CCandBank "
strSQL = strSQL & "WHERE CCandBank.ProcessedDate >=Me!Combo0 AND
CCandBank.ProcessedDate <= Me!Combo2 "
strSQL = strSQL & "AND CCandBank.SortCode Like ""%"" & Me![Combo4] &
""%"" "
strSQL = strSQL & "AND CCandBank.TransactionDetails Like ""%"" &
Me!Text19 & ""%"" & Me!Combo51 & CCandBank.TransactionDetails Like ""%"" &
Me!Text39 & ""%"""
strSQL = strSQL & " ORDER BY CCandBank.ProcessedDate;"
Debug.Print strSQL
Set rs = CurrentDb.CreateQueryDef("Purchase", strSQL)
End Sub
It runs OK till the last line where it gives a typemismatch but generates
the query anyway. This is what it put in the SQL design window
SELECT CCandBank.ProcessedDate, CCandBank.CardUser,
CCandBank.TransactionDetails, CCandBank.Amount, CCandBank.SortCode
FROM CCandBank
WHERE (((CCandBank.ProcessedDate)>=[Me]![Combo0] And
(CCandBank.ProcessedDate)<=[Me]![Combo2]) AND ((CCandBank.SortCode) ALike
"%"
& [Me]![Combo4] & "%") AND (([CCandBank].[TransactionDetails] ALike "%" &
[Me]![Text19] & "%" & [Me]![Combo51] & [CCandBank].[TransactionDetails])
ALike "%" & [Me]![Text39] & "%"))
ORDER BY CCandBank.ProcessedDate;
The Design Grid looks like this:-
Col 1 Field ProcessedDate Criteria >=[Me]![Combo0] And <=[Me]![Combo2] I
entered when prompted 1/1/05, 1/1/06
Col 2 Field CardUser
Col 3 Field TransactionDetails
Col 4 Field Amount
Col 5 Field SortCode Criteria ALike "%" & [Me]![Combo4] & "%" entered SMKT
Col 6 Field [CCandBank].[TransactionDetails] ALike "%" & [Me]![Text19] &
"%"
& [Me]![Combo51] & [CCandBank].[TransactionDetails]
Criteria ALike "%" & [Me]![Text39] & "%" entered col for text19, OR
for combo51and wool for text39.
It returned no records.
Modifying the SQL window to select Date, sortcode, text19 Combo51 (as OR)
Date, sortcode, text39 FINDS ALL 6000 plus records.
SQLlooks like
SELECT CCandBank.ProcessedDate, CCandBank.CardUser,
CCandBank.TransactionDetails, CCandBank.Amount, CCandBank.SortCode
FROM CCandBank
WHERE ((((((CCandBank.ProcessedDate)>=Me!Combo0 And
(CCandBank.ProcessedDate)<=Me!Combo2) And ((CCandBank.TransactionDetails)
ALike "%" & Me!Text39 & "%") And ((CCandBank.SortCode) ALike "%" &
Me!Combo4
& "%")) & " " & Me!COMBO51 & " " & (((CCandBank.ProcessedDate)>=Me!Combo0
And
(CCandBank.ProcessedDate)<=Me!Combo2) And ((CCandBank.TransactionDetails)
ALike "%" & Me!Text19 & "%") And ((CCandBank.SortCode) ALike "%" &
Me!Combo4
& "%")))<>False))
ORDER BY CCandBank.ProcessedDate;
The Design Grid looks like this:-
Col 1 Field ProcessedDate I entered when prompted 1/1/05, 1/1/06
Col 2 Field CardUser
Col 3 Field TransactionDetails
Col 4 Field Amount
Col 5 Field SortCode Ientered SMKT
Col 6 Field ((([CCandBank].[ProcessedDate])>=[Me]![Combo0] And
([CCandBank].[ProcessedDate])<=[Me]![Combo2]) And
(([CCandBank].[TransactionDetails]) ALike "%" & [Me]![Text39] & "%") And
(([CCandBank].[SortCode]) ALike "%" & [Me]![Combo4] & "%")) & " " &
[Me]![COMBO51] & " " & ((([CCandBank].[ProcessedDate])>=[Me]![Combo0] And
([CCandBank].[ProcessedDate])<=[Me]![Combo2]) And
(([CCandBank].[TransactionDetails]) ALike "%" & [Me]![Text19] & "%") And
(([CCandBank].[SortCode]) ALike "%" & [Me]![Combo4] & "%"))
Criteria <>False
It returned all 600 plus records.
The query seems to be interpreting Combo51 differently. I don'tknow why.
It
interprets the text input correctly but cannot interpret the Combo51 (as
OR)
as a reserved SQL word.
This what I need help with. This is the second time I have sent this as
the
first time the reply crashed and I don't know if my reply got through.
Regards Derick
Regards Derick
Duane Hookom said:
You tell us where Combo51 appears in the query grid like under what
column?
The same with the <>False.
--
Duane Hookom
MS Access MVP
Hi
I have tried using Forms!YourForm!ComboBox and the Me! syntax and both
work
so I use the shorter version.
The [Me]![COMBO51] is on a form that provides ;OR;AND;AND NOT; etc from
a
value list with the idea that this would replace the "OR" in the first
version of the query that works as I want. The query understands the
text
from the text boxes correctly but does not see the [Me]![COMBO51] input
as
OR
and I do not know what it sees but it returns every record not the
desired
selection.
As to the <>False)) Access inserted that. I am not sure what it
intended
either.
Derick
I'm not sure what [Me]![COMBO51] and <>False are doing in there. Is
this
from your SQL view? Have you played with it in design view?
--
Duane Hookom
MS Access MVP
THIS WORKS AS I WANT:-
SELECT CCandBank.ProcessedDate, CCandBank.CardUser,
CCandBank.TransactionDetails, CCandBank.Amount, CCandBank.SortCode
FROM CCandBank
WHERE (((CCandBank.ProcessedDate)>=Me!Combo0 And
(CCandBank.ProcessedDate)<=Me!Combo2) And
((CCandBank.TransactionDetails)
ALike "%" & Me!Text39 & "%") And ((CCandBank.SortCode) ALike "%" &
Me!Combo4
& "%")) OR (((CCandBank.ProcessedDate)>=Me!Combo0 And
(CCandBank.ProcessedDate)<=Me!Combo2) And
((CCandBank.TransactionDetails)
ALike "%" & Me!Text19 & "%") And ((CCandBank.SortCode) ALike "%" &
Me!Combo4
& "%"))
ORDER BY CCandBank.ProcessedDate;
THIS RETURNS EVERY RECORD:-
SELECT CCandBank.ProcessedDate, CCandBank.CardUser,
CCandBank.TransactionDetails, CCandBank.Amount, CCandBank.SortCode
FROM CCandBank
WHERE (((((([CCandBank].[ProcessedDate])>=[Me]![Combo0] And
([CCandBank].[ProcessedDate])<=[Me]![Combo2]) And
(([CCandBank].[TransactionDetails]) ALike "%" & [Me]![Text39] & "%")
And
(([CCandBank].[SortCode]) ALike "%" & [Me]![Combo4] & "%")) &
[Me]![COMBO51]
& ((([CCandBank].[ProcessedDate])>=[Me]![Combo0] And
([CCandBank].[ProcessedDate])<=[Me]![Combo2]) And
(([CCandBank].[TransactionDetails]) ALike "%" & [Me]![Text19] & "%")
And
(([CCandBank].[SortCode]) ALike "%" & [Me]![Combo4] &
"%")))<>False))
ORDER BY CCandBank.ProcessedDate;
I have been searching and reading for weeks now trying to get the
second
alternative to work without success.