Invalid SQL Statement

iheartvba

New member
Local time
Tomorrow, 01:53
Joined
Apr 3, 2008
Messages
3
Hi
I am getting the following error when i click cmdFFR (See note1): Invalid SQL statement, expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT' or 'UPDATE'. I can't figure out why this is. Spelling all seems to be correct.

Public Dimensions are as follow:

Code:
Option Compare Database
Option Explicit 
Public cnn As ADODB.Connection
Public rst As New ADODB.Recordset
(Note1)

Code:
Private Sub cmdFFR_Click()
Dim intFFR As Byte
Set cnn = CurrentProject.Connection
rst.Open "qryCountYearsPerReceipt", cnn, adOpenKeyset, adLockOptimistic
  With rst
      intAddFFRYears = !CountOfYear
   End With
End Sub

qryCountYearsPerReceipt (from Private Sub cmdFFR_Click) above is made via Query Builder the code is as follows:


Code:
SELECT qryGroupByYearsPerReceipt.ReceiptID, Count(qryGroupByYearsPerReceipt.Year) AS CountOfYear
FROM qryGroupByYearsPerReceipt
GROUP BY qryGroupByYearsPerReceipt.ReceiptID
HAVING (((qryGroupByYearsPerReceipt.ReceiptID)=[Forms]![frmFFR]![cboRcptID]));

qryGroupByYearsPerReceipt (which is a query from which qryCountYearsPerReceipt is made) is also made by the query builder and code is as follows :

Code:
SELECT qryGroupByYearsPerReceipt.ReceiptID, Count(qryGroupByYearsPerReceipt.Year) AS CountOfYear
FROM qryGroupByYearsPerReceipt
GROUP BY qryGroupByYearsPerReceipt.ReceiptID
HAVING (((qryGroupByYearsPerReceipt.ReceiptID)=[Forms]![frmFFR]![cboRcptID]));

I have tried looking up reference books, google, examples from other recordset functions i have done which are working fine (but those are all strings I have written in VBA they are not this complex), I have tried being frustrated and I have tried pulling my hair, nothing is working. Any help would be much appreciated.
 
Without your database it is difficult to pinpoint the problem. However you could try this:
Use WHERE instead of HAVING.
Code:
SELECT qryGroupByYearsPerReceipt.ReceiptID, Count(qryGroupByYearsPerReceipt.Year) AS CountOfYear
FROM qryGroupByYearsPerReceipt
WHERE (((qryGroupByYearsPerReceipt.ReceiptID)=[Forms]![frmFFR]![cboRcptID]))
GROUP BY qryGroupByYearsPerReceipt.ReceiptID
HTH:D
 

Users who are viewing this thread

Back
Top Bottom