Count the number of rows in a query result

Solved
angelo2night -  
 DALAF -
Hello,

I am trying to code in VBA under Access 2007 a macro that would allow me to count the number of rows in a query result.

I have a table where I extract the desired information through a query and display it.
What I can't do is create a MsgBox that shows me the number of rows.

RecapChantierEffectue: this is the name of my query that allows me to display the desired information.

Here is my code that executes upon a click:

Private Sub Commande0_Click()

Dim cpt As Integer

'Execution of the query
'DoCmd.OpenQuery "Queryname",acReadOnly to allow the user to view only
DoCmd.OpenQuery "RecapChantierEffectue", acReadOnly

cpt = DCount("*&, "RecapChantierEffectue")

MsgBox ("you have completed a total of " &cpt " construction sites")

End Sub

The DCount does not work! Please help me!

Configuration: Windows Vista / Firefox 8.0

2 réponses

f894009 Posted messages 17417 Registration date   Status Membre Last intervention   1 717
 
Hello,

this should work:

cpt=DCount ("*","RecapChantierEffectue")

Best regards
3