I have code for Office Automation. Data in Access turns into a chart in Excel. The code works normally as expected. But now I receive an error:
Error -2147217900 (Invalid SQL statement; expected DELETE, INSERT, PROCEDURE, SELECT or UPDATE, line 230
The code (part of it) is like this:
Dim conQuery As String
110 conQuery = "[ChartDataOGAEpH]"
' Create recordset.
‘Debug.Print conQuery
220 Set rst = New ADODB.Recordset
230 rst.Open _
Source:=conQuery, _
ActiveConnection:=CurrentProject.Connection
Error when the SQL is:
SELECT Format([MätDatum],"Short Date") AS Registered, [Jäsprotokoll rader].OG, [Jäsprotokoll rader].SG AS AE, [Jäsprotokoll rader].pH
FROM Jäsprotokoll INNER JOIN [Jäsprotokoll rader] ON Jäsprotokoll.JäsprotokollID = [Jäsprotokoll rader].JäsprotokollID
WHERE (((Format([MätDatum],"Short Date")) Is Not Null) AND (([Jäsprotokoll rader].SG) Is Not Null) AND ((Jäsprotokoll.JäsprotokollID)=[Forms]![Jäsprotokoll historiskt]![JäsprotokollID]))
ORDER BY Format([MätDatum],"Short Date");
Although the output of the query is:
ChartDataOGAEpH | |||
Registered | OG | AE | pH |
2021-09-07 | 12,9 | 12,9 | 5,2 |
2021-09-08 | 12,9 | 9,5 | 4,6 |
2021-09-09 | 12,9 | 6 | 4,35 |
2021-09-10 | 12,9 | 3 | 4,3 |
2021-09-13 | 12,9 | 2,5 | 4,4 |
2021-09-14 | 12,9 | 2.5 | 4,41 |
2021-09-15 | 12,9 | 2,5 | 4,48 |
What am I doing wrong?
ASKER
Dim rst as DAO.Recordset
Dim strSQL as String
strSQL = ' Your sql
set rst = CurrentDb.OpenRecordset(strSQL)
Debug.print rst.Recordcount
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
TRUSTED BY
If the connection is directly to SQL then you have check the commands ...e.g SQL doesn't have Format