Sammentælling går galt.
Hej gutterneJeg har en liste over kunder og deres køb. Jeg udskriver dette til en rapport, på følgende format:
Kunde1
Produkt1 20,-
Produkt2 10.-
Kunde2
Produkt99 ...
Det fylder pt 1½ A4-side.
Mit problem er, at det tal, der står først på side 2, bliver talt med 2 gange.
Herunder følger koden (har lige overtaget databasen, fra ham, der blev fyret til min fordel, så ja, det er lidt specielt...)
Det er GrandTotalTotal, der er den, som bliver for stor.
--CODE--
Option Compare Database
Dim iDivision(6) As Double
Dim iDivisionTotal(6) As Double
Dim iGrandTotal As Double
Dim sWhere As String
Private Sub Rapporthoved_Format(Cancel As Integer, FormatCount As Integer)
'Nulstiller totaler
For i = 1 To 6
iDivisionTotal(i) = 0
Next
iGrandTotal = 0
'Henter kriterier
sWhere = ConcatStr3
End Sub
Private Sub Detaljesektion_Format(Cancel As Integer, FormatCount As Integer)
Dim oRS As ADODB.Recordset
Dim sSQL As String
Dim iDivisionSum(6) As Double
Set oRS = New ADODB.Recordset
oRS.CursorLocation = adUseClient
For i = 1 To 6
If Not IsNull(iDivision(i)) Then
sSQL = "SELECT Sum(Ordre.Pris) AS SumOfOrdervärde " & _
"FROM Distributør INNER JOIN (Division RIGHT JOIN (Produkter INNER JOIN (Konsolideret INNER JOIN (Kunder INNER JOIN Ordre ON Kunder.Kundenr = Ordre.Kundenr) ON Konsolideret.Id = Kunder.Konsolideret) ON Produkter.Produktnr = Ordre.Produktnr) ON Division.DivID = Produkter.Division) ON Distributør.Id = Ordre.Distributør " & _
"WHERE Division.DivId=" & iDivision(i) & " AND Konsolideret.Id=" & txtID
If Not sWhere = "" Then
sSQL = sSQL & " AND " & sWhere
End If
oRS.Open sSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If Not IsNull(oRS(0)) Then
iDivisionSum(i) = oRS(0)
iDivisionTotal(i) = iDivisionTotal(i) + iDivisionSum(i)
End If
oRS.Close
End If
Next
If Not iDivisionSum(1) = 0 Then
txtDiv1 = iDivisionSum(1)
Else
txtDiv1 = ""
End If
If Not iDivisionSum(2) = 0 Then
txtDiv2 = iDivisionSum(2)
Else
txtDiv2 = ""
End If
If Not iDivisionSum(3) = 0 Then
txtDiv3 = iDivisionSum(3)
Else
txtDiv3 = ""
End If
If Not iDivisionSum(4) = 0 Then
txtDiv4 = iDivisionSum(4)
Else
txtDiv4 = ""
End If
If Not iDivisionSum(5) = 0 Then
txtDiv5 = iDivisionSum(5)
Else
txtDiv5 = ""
End If
If Not iDivisionSum(6) = 0 Then
txtDiv6 = iDivisionSum(6)
Else
txtDiv6 = ""
End If
txtGrandTotal = iDivisionSum(1) + iDivisionSum(2) + iDivisionSum(3) + iDivisionSum(4) + iDivisionSum(5) + iDivisionSum(6)
iGrandTotal = iGrandTotal + txtGrandTotal
End Sub
Private Sub Rapportfod_Format(Cancel As Integer, FormatCount As Integer)
txtDivTotal1 = iDivisionTotal(1)
txtDivTotal2 = iDivisionTotal(2)
txtDivTotal3 = iDivisionTotal(3)
txtDivTotal4 = iDivisionTotal(4)
txtDivTotal5 = iDivisionTotal(5)
txtDivTotal6 = iDivisionTotal(6)
txtGrandTotalTotal = iGrandTotal
End Sub
Private Sub Report_Open(Cancel As Integer)
Dim oRS As ADODB.Recordset
Dim sSQL As String
Dim iIndex As Long
Dim sDivision(6) As String
'Opdaterer kriterier
FrDate.Visible = False
ToDate.Visible = False
DistType.Visible = False
Dist.Visible = False
Avd.Visible = False
UnderDiv.Visible = False
Kat.Visible = False
Produkt.Visible = False
Saelger.Visible = False
Kund.Visible = False
Akt.Visible = False
Kgr.Visible = False
If [Forms]![FsgRapport]![ifFraDato] = -1 Then FrDate.Visible = True
If [Forms]![FsgRapport]![ifTilDato] = -1 Then ToDate.Visible = True
If [Forms]![FsgRapport]![ifDistType] = -1 Then DistType.Visible = True
If [Forms]![FsgRapport]![ifDist] = -1 Then Dist.Visible = True
If [Forms]![FsgRapport]![ifDiv] = -1 Then Avd.Visible = True
If [Forms]![FsgRapport]![ifUnderDiv] = -1 Then UnderDiv.Visible = True
If [Forms]![FsgRapport]![ifKat] = -1 Then Kat.Visible = True
If [Forms]![FsgRapport]![ifProdukt] = -1 Then Produkt.Visible = True
If [Forms]![FsgRapport]![ifSaelger] = -1 Then Saelger.Visible = True
If [Forms]![FsgRapport]![ifKunde] = -1 Then Kund.Visible = True
If [Forms]![FsgRapport]![IfKonsolideret] = -1 Then Akt.Visible = True
If [Forms]![FsgRapport]![ifSegment] = -1 Then Kgr.Visible = True
Set oRS = New ADODB.Recordset
oRS.CursorLocation = adUseClient
oRS.Open "SELECT * FROM Division ORDER BY Navn", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
iIndex = 1
Do Until oRS.EOF
iDivision(iIndex) = oRS("DivID")
sDivision(iIndex) = oRS("Navn")
iIndex = iIndex + 1
oRS.MoveNext
Loop
lblDivTitel1.Caption = " " & sDivision(1)
lblDivTitel2.Caption = " " & sDivision(2)
lblDivTitel3.Caption = " " & sDivision(3)
lblDivTitel4.Caption = " " & sDivision(4)
lblDivTitel5.Caption = " " & sDivision(5)
lblDivTitel6.Caption = " " & sDivision(6)
End Sub
--/CODE--