Why does a query count (with GROUP BY) indicate more records than there are??

  • Thread starter Thread starter Hyphessobricon
  • Start date Start date
H

Hyphessobricon

Hallo,

Indeed, a count of a query with a group by function gives more records than
there are and so for-next structures don't function.
How is this to be mended.
Anyone? Everyone in fact.
Answers are greatly appreciated.
 
Hi,

Post some code.

Ken
-----------
Hallo,

Indeed, a count of a query with a group by function gives more records than
there are and so for-next structures don't function.
How is this to be mended.
Anyone? Everyone in fact.
Answers are greatly appreciated.
 
Ken Tucker said:
Hi,

Post some code.

Ken
-----------
Hallo,

Indeed, a count of a query with a group by function gives more records
than
there are and so for-next structures don't function.
How is this to be mended.
Anyone? Everyone in fact.
Answers are greatly appreciated.

So, in my Module1
the count says : 5 rows in table
and th'n an error no row at 2
in the query there are indeed only 2 rows, an din the table there are 5, but
I work with the query.

Private Sub brandstof1() 'huisbrandolie

i = dtqBs1.Rows.Count '=dtBS1 is for the tbl, dtqBs1 is the query,
everything containing q is for the query

MsgBox("brandstofrijen " & i) '= here I get the 5 rows

Dim dattum As Date

For i = 0 To i - 1

'query gebruikt om de laatst ingevoerde te tonen

If dsqBrandstof1.Tables(0).Rows(i).Item("Brandstofjaar") = CInt(Year(Now()))
Then '= the query dataset

frmVariabele.lblStookVJ.Text = Format(dsqBrandstof1.Tables(0).Rows(i -
1).Item("SomvanBrandstof"), "0.00")

frmVariabele.txtGasT.Text =
Format(dsqBrandstof1.Tables(0).Rows(i).Item("SomvanBrandstof"), "0.00")

frmVariabele.lblVersStook.Text = Format(Val(frmVariabele.lblStookVJ.Text) -
Val(frmVariabele.txtGasT.Text), "0.00")

End If

Next i

i = dsBrandstof1.Tables(0).Rows.Count =that is the regular table dataset

For i = 0 To i - 1

If dsBrandstof1.Tables(0).Rows(i).Item("Brandstofdatum") > dattum Then

dattum = dsBrandstof1.Tables(0).Rows(i).Item("Brandstofdatum")

End If

Next i

For i = 0 To i - 1

If dsBrandstof1.Tables(0).Rows(i).Item("Brandstofdatum") = dattum Then

frmVariabele.txtGas.Text =
Format(dsBrandstof1.Tables(0).Rows(i).Item("Brandstof"), "0.00")

frmVariabele.txtGasDat.Text =
dsBrandstof1.Tables(0).Rows(i).Item("Brandstofinfo")

frmVariabele.txtGadat.Text =
dsBrandstof1.Tables(0).Rows(i).Item("Brandstofdatum")

End If

Next

End Sub
 
Hi,

Think the problem is with your for loop. for i=0 to i-1. try this
instead

dim intRows as integer = dtqBs1.Rows.Count

For i = 0 To intRows - 1


Ken
------------------------


Ken Tucker said:
Hi,

Post some code.

Ken
-----------
Hallo,

Indeed, a count of a query with a group by function gives more records
than
there are and so for-next structures don't function.
How is this to be mended.
Anyone? Everyone in fact.
Answers are greatly appreciated.

So, in my Module1
the count says : 5 rows in table
and th'n an error no row at 2
in the query there are indeed only 2 rows, an din the table there are 5, but
I work with the query.

Private Sub brandstof1() 'huisbrandolie

i = dtqBs1.Rows.Count '=dtBS1 is for the tbl, dtqBs1 is the query,
everything containing q is for the query

MsgBox("brandstofrijen " & i) '= here I get the 5 rows

Dim dattum As Date

For i = 0 To i - 1

'query gebruikt om de laatst ingevoerde te tonen

If dsqBrandstof1.Tables(0).Rows(i).Item("Brandstofjaar") = CInt(Year(Now()))
Then '= the query dataset

frmVariabele.lblStookVJ.Text = Format(dsqBrandstof1.Tables(0).Rows(i -
1).Item("SomvanBrandstof"), "0.00")

frmVariabele.txtGasT.Text =
Format(dsqBrandstof1.Tables(0).Rows(i).Item("SomvanBrandstof"), "0.00")

frmVariabele.lblVersStook.Text = Format(Val(frmVariabele.lblStookVJ.Text) -
Val(frmVariabele.txtGasT.Text), "0.00")

End If

Next i

i = dsBrandstof1.Tables(0).Rows.Count =that is the regular table dataset

For i = 0 To i - 1

If dsBrandstof1.Tables(0).Rows(i).Item("Brandstofdatum") > dattum Then

dattum = dsBrandstof1.Tables(0).Rows(i).Item("Brandstofdatum")

End If

Next i

For i = 0 To i - 1

If dsBrandstof1.Tables(0).Rows(i).Item("Brandstofdatum") = dattum Then

frmVariabele.txtGas.Text =
Format(dsBrandstof1.Tables(0).Rows(i).Item("Brandstof"), "0.00")

frmVariabele.txtGasDat.Text =
dsBrandstof1.Tables(0).Rows(i).Item("Brandstofinfo")

frmVariabele.txtGadat.Text =
dsBrandstof1.Tables(0).Rows(i).Item("Brandstofdatum")

End If

Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top