SQL SELECT ... HAVING and error 2001

L

Little Daddy

When this code executes it generates error 2001 "you canceled the previous
operation" right after the DoCmd.OpenQuery and doesn't open the actual query.
If the HAVING statement is modified not have the OR operator it will work.

strSQLTemp2 = "SELECT First(PartNum) AS FirstOfPartNum, SerialNum,
First(PartDesc) AS FirstOfPartDesc, First(EmpNum) AS FirstOfEmpNum,
First(EntryDate) AS FirstOfEntryDate, First(Pass_Fail) AS FirstOfPass_Fail
FROM tblTestLog " _
& "GROUP BY SerialNum " _
& "HAVING (((First(PartNum)) Like '" & strPNum _
& "' AND " & "(First(Pass_Fail)) Like '" & strPass_Fail _
& "' AND " & "(SerialNum)<> '" & "0" _
& "' AND " & "(First(EntryDate)) Between " & "#" & dteStart & "#" &
" AND " & "#" & dteStop & "#)" & " Or " & "((First(PartNum)) Like '" &
strPNum _
& "' AND " & "(First(Pass_Fail)) Like '" & strPass_Fail _
& "' AND " & "(First(EmpNum))<> '" & 0 _
& "' AND " & "(First(EntryDate)) Between " & "#" & dteStart & "#" &
" AND " & "#" & dteStop & "#))"

strSQL = strSQLTemp2

Set dbs = CurrentDb()

Set qdef = dbs.CreateQueryDef("qryPassTable", strSQL)
DoCmd.OpenQuery "qryPassTable", acNormal, acReadOnly

Thanks
Little Daddy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top