smartpat19
Board Regular
- Joined
- Sep 3, 2014
- Messages
- 114
HI, I am having issues with my current SQL Statement.
my immediate window is throwing the current error: "-2147217900:Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'."
I am trying to determine the number of records in the Dates table based on two fields.
Thank you,
Patrick
my immediate window is throwing the current error: "-2147217900:Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'."
I am trying to determine the number of records in the Dates table based on two fields.
VBA Code:
Private Sub cmdSelectBySQL_Click()
On Error GoTo Catch
Dim strSql As String
Dim cn As ADODB.Connection
Dim objRst As ADODB.Recordset
Dim lngCount As Long
Dim project As String
Dim report As String
report = Sheets("Master").Range("f5")
project = Sheets("Master").Range("f6")
'' Get all categories
strSql = "SELECT Count(*) FROM Dates HAVING (((([Dates].[Project_Number]))='" & project & "' And (([Dates].[Report_Name]))='" & report & "'));"
Set objRst = New ADODB.Recordset
objRst.Open strSql, cn.Connection, adOpenForwardOnly
lngCount = objRst!cnt
Debug.Print "Record count: " & lngCount
'' Clean up
objRst.Close
Set objRst = Nothing
Exit Sub
Catch:
MsgBox "cmdSelectBySQL_Click()" & vbCrLf & vbCrLf & _
"Error#: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub
Thank you,
Patrick