I have a problem that I can't seem to correct. I have the following code
and then
and farther down
Startdate is set to a value.Debug.print Startdate is 01/04/2007 in dd/mm/yy format
EndDate is set to a value. Debug.print Enddate is 30/06/2007 in dd/mm/yy format. This code follows.
The first time the .execute statements is issued, it returns the right values. The second time it is issued, it seems to think then start date is mm/dd/yy format and returns the wrong values. However, if I have 2 'Set rsGSTAmount = cmdGSTSalesAmount.Execute' statements in a row, it returns the right values each time.
This is used with an access database and InvoiceDate is a DateTime value.
David Paulson
Code:
Dim cmdGSTSalesAmount As ADODB.command
Dim prm As ADODB.Parameter
Dim rsGSTAmount as ADODB.recordset
Dim StartDate As Date
Dim EndDate As Date
Code:
Set cmdGSTSalesAmount = New ADODB.command
cmdGSTSalesAmount.ActiveConnection = cnAccounting
cmdGSTSalesAmount.CommandText = "SELECT sum(TotalGSTSales) as MonthTotalGSTSales,sum(TotalNonGSTSales) as MonthTotalNonGSTSales, sum(GSTAmount) as MonthGSTTotal, sum(DebitTotal) as MonthInvoiceAmount FROM Invoices WHERE Printed = True AND DebitTransType = 'I' AND InvoiceDate BETWEEN ? AND ?"
cmdGSTSalesAmount.CommandType = adCmdText
Set prm = cmdGSTSalesAmount.CreateParameter("Start", adDate, adParamInput)
cmdGSTSalesAmount.Parameters.Append prm
Set prm = cmdGSTSalesAmount.CreateParameter("End", adDate, adParamInput)
cmdGSTSalesAmount.Parameters.Append prm
Startdate is set to a value.Debug.print Startdate is 01/04/2007 in dd/mm/yy format
EndDate is set to a value. Debug.print Enddate is 30/06/2007 in dd/mm/yy format. This code follows.
Code:
cmdGSTSalesAmount.Parameters("Start").Value = StartDate
cmdGSTSalesAmount.Parameters("End").Value = EndDate
Set rsGSTAmount = cmdGSTSalesAmount.Execute
This is used with an access database and InvoiceDate is a DateTime value.
David Paulson