Predmet:Re: Problem sa DMAX
ja ipak odradio po svom i radi mi super
Function AnalizaBU11(Optional Red As Integer = 2, Optional Konto As String = "6%")
'---------------------------------------------
-------------
Dim Db As DAO.Database
Dim Rs As DAO.Recordset
Dim SQL As String
Dim I As Integer
SQL = "SELECT top " & Red & " Sum([duguje]-[potrazuje]) AS Iznos, Left([stavgk]![konto],3) AS Sink " _
& "FROM AKTIV INNER JOIN stavgk ON (AKTIV.ObracinskiPeriod = stavgk.ObracinskiPeriod) AND (AKTIV.godina = stavgk.period) AND (AKTIV.firma = stavgk.firmaID) " _
& "WHERE Left([stavgk]![konto],3) ALike '" & Konto & "'" _
& " GROUP BY Left(konto,3) " _
& "HAVING Sum([duguje]-[potrazuje])<0 " _
& "ORDER BY Sum([duguje]-[potrazuje])"
Set Db = CurrentDb()
Set Rs = Db.OpenRecordset(SQL)
For I = 1 To Red
Konto = Rs!sink
Rs.MoveNext
Next I
SQL = "SELECT top " & Red & " Sum([duguje]-[potrazuje]) AS Iznos, Left([stavgk]![konto],3) AS Sink " _
& "FROM AKTIV INNER JOIN stavgk ON (AKTIV.ObracinskiPeriod = stavgk.ObracinskiPeriod) AND (AKTIV.godina = stavgk.period) AND (AKTIV.firma = stavgk.firmaID) " _
& "WHERE Left([stavgk]![konto],3) ALike '" & Konto & "'" _
& " GROUP BY Left(konto,3) " _
& "HAVING Sum([duguje]-[potrazuje])<0"
Set BU11 = Db.OpenRecordset(SQL)
AnalizaBU11 = BU11!Iznos
End Function