[AccessD] Query Problem

Rocky Smolin rockysmolin at bchacc.com
Mon Nov 16 13:08:27 CST 2009


Dear List:

I have a query in code as a SQL statement which I use to open a recordset in
DAO.  It retrieves 16 records but it should retrieve 20. I display this SQL
text on the calling form so I can cut it and paste it into the SQL view of a
query and run it there.  When I run it as a query it retrieves all 20
records. The four missing records from the DAO recordset are the ones where
the   field fldUSRHeaderAdjustment is TRUE. 

Question is why the records retrieved would differ when using the same
string to open a DAO recordset and pasting the SQL into a query_

 

Here*s the SQL 

strSQL = "SELECT tblLicensee.fldLicenseeID, tblLicensee.fldLicenseeName, " _
    & "tblUSRDetail.fldUSRDetailQuantity, tblUSRDetail.fldUSRDetailShipDate,
" _
    & "tblUSRHeader.fldUSRHeaderShipmentYear,
tblUSRHeader.fldUSRHeaderShipmentQuarter, " _
    & "tblUSRHeader.fldUSRHeaderAdjustment,
tblUSRHeader.fldUSRHeaderReportingQuarter, " _
    & "tblUSRHeader.fldUSRHeaderReportingYear,
Trim(Str([fldUSRHeaderShipmentYear])) & " _
    & "Trim(Str([fldUSRHeaderShipmentQuarter])) AS ShipYearQuarter FROM
tblUSRHeader " _
    & "INNER JOIN ((tblLicensee INNER JOIN tblProduct ON
tblLicensee.fldLicenseeID = " _
    & "tblProduct.fldLicenseeID) INNER JOIN tblUSRDetail ON
tblProduct.fldProductID = " _
    & "tblUSRDetail.fldProductID) ON tblUSRHeader.fldUSRHeaderID = " _
    & "tblUSRDetail.fldUSRHeaderID WHERE (((tblLicensee.fldLicenseeName)
Like '" _
    & Me.txtCDLIHScenarioPrefix & "*') AND
((Trim(Str([fldUSRHeaderShipmentYear])) & " _
    & "Trim(Str([fldUSRHeaderShipmentQuarter])))<='" & Me.cboShipmentYear _
    & Me.cboShipmentQuarter & "') AND
((tblProduct.fldProductCDLInvoiceEligible)=True) AND " _
    & "((tblUSRHeader.fldUSRHeaderDeleteFlag)=False) AND " _
    & "((tblUSRDetail.fldUSRDetailDeleteFlag)=False)) ORDER BY
tblLicensee.fldLicenseeName, " _
    & "tblUSRHeader.fldUSRHeaderShipmentYear,
tblUSRHeader.fldUSRHeaderShipmentQuarter, " _
    & "tblUSRHeader.fldUSRHeaderAdjustment DESC ,
Trim(Str([fldUSRHeaderShipmentYear])) & " _
    & "Trim(Str([fldUSRHeaderShipmentQuarter]));"

in the code. And here it is cut from the text box and pasted into a query

SELECT tblLicensee.fldLicenseeID, tblLicensee.fldLicenseeName,
tblUSRDetail.fldUSRDetailQuantity, tblUSRDetail.fldUSRDetailShipDate,
tblUSRHeader.fldUSRHeaderShipmentYear,
tblUSRHeader.fldUSRHeaderShipmentQuarter,
tblUSRHeader.fldUSRHeaderAdjustment,
tblUSRHeader.fldUSRHeaderReportingQuarter,
tblUSRHeader.fldUSRHeaderReportingYear,
Trim(Str([fldUSRHeaderShipmentYear])) &
Trim(Str([fldUSRHeaderShipmentQuarter])) AS ShipYearQuarter FROM
tblUSRHeader INNER JOIN ((tblLicensee INNER JOIN tblProduct ON
tblLicensee.fldLicenseeID = tblProduct.fldLicenseeID) INNER JOIN
tblUSRDetail ON tblProduct.fldProductID = tblUSRDetail.fldProductID) ON
tblUSRHeader.fldUSRHeaderID = tblUSRDetail.fldUSRHeaderID WHERE
(((tblLicensee.fldLicenseeName) Like 'C7-*') AND
((Trim(Str([fldUSRHeaderShipmentYear])) &
Trim(Str([fldUSRHeaderShipmentQuarter])))<='20104') AND
((tblProduct.fldProductCDLInvoiceEligible)=True) AND
((tblUSRHeader.fldUSRHeaderDeleteFlag)=False) AND
((tblUSRDetail.fldUSRDetailDeleteFlag)=False)) ORDER BY
tblLicensee.fldLicenseeName, tblUSRHeader.fldUSRHeaderShipmentYear,
tblUSRHeader.fldUSRHeaderShipmentQuarter,
tblUSRHeader.fldUSRHeaderAdjustment DESC ,
Trim(Str([fldUSRHeaderShipmentYear])) &
Trim(Str([fldUSRHeaderShipmentQuarter]));

MTIA,
 
Rocky
 






More information about the AccessD mailing list