Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql statement not working in code, will work when in query 1

Status
Not open for further replies.

lwilly

Technical User
Apr 11, 2000
84
0
0
US
I have this sql statement in a module

strSQL = "SELECT SUM (IVC_QTY * InvoiceUnitPrice)AS Sales"
strSQL = strSQL & " FROM tblSalesDbMaster"
strSQL = strSQL & " WHERE IVC_DATE >= " & dteBegin
strSQL = strSQL & &quot; AND IVC_DATE <= &quot; & dteEnd

Set rst = dbs.OpenRecordset(strSQL)

GetTotalSales = rst![Sales]

When run this statement it returns a null value. When I debug this statement and paste it into a query it returns the number I am looking for. Can someone explain why it works one way but not the other.

Thanks
 
Try:

strSQL = &quot;SELECT SUM (IVC_QTY * InvoiceUnitPrice)AS Sales&quot;
strSQL = strSQL & &quot; FROM tblSalesDbMaster&quot;
strSQL = strSQL & &quot; WHERE IVC_DATE >= #&quot; & dteBegin & &quot;#&quot;
strSQL = strSQL & &quot; AND IVC_DATE <= #&quot; & dteEnd & &quot;#;&quot;
 
Thanks for the quick response. Your response was correct and I appreciate you pointing out the errors of my ways.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top