1

When I try to use ADODB to connect on an Excel DB, it says:

you try to execute a query without a specified expression <Destinataire>

Here's my code:

MyQuery = "Select Destinataire, SUM(" & Entete & ") AS NombreTotal FROM [Feuil1$] " _
                         & "WHERE [DateMad] Between #" _
                         & Format(date_deb, "yyyy/mm/dd") _
                         & "# And #" & Format(date_fin, "yyyy/mm/dd") & "#" & Query3 & ""

                    objRecordSet.Open MyQuery, objConnection, adOpenStatic, adLockOptimistic

What's wrong with it?

4

1 回答 1

3

You forgot the group by

The query should look like this

Select Destinataire, SUM(NbCompteurElec) AS NombreTotal FROM [Feuil1$] 
WHERE [DateMad] Between #2012/10/22# And #2012/10/26# And [Destinataire] = 'REL12'
Group By Destinataire

In your code it should be like this

MyQuery = "Select Destinataire, SUM(" & Entete & ") AS NombreTotal FROM [Feuil1$] " _
                         & "WHERE [DateMad] Between #" _
                         & Format(date_deb, "yyyy/mm/dd") _
                         & "# And #" & Format(date_fin, "yyyy/mm/dd") & "#" & Query3 & " Group By Destinataire"

Here's a tuto about the GROUP BY clause

于 2012-11-02T13:06:17.960 回答