Russian version
English version
| | | | SILICON TAIGA | ISDEF | CD | | | | | | | |
 
 
 
IT-
 
 
 
RSS-

Altu

N- . DCount, DMax ..
PublicFunctionDPersent(strNameFieldsAsString,strNameTBLAsString,OptionalstrFilterAsString="",OptionalpAsInteger)AsVariant
':altu28.11.2006.
'
'DCount,DMax..
'strNameFields-
'strNameTBL-
'strFilter-
'p-0-100

DimrstAsADODB.Recordset
DimlngCountAsLong
Dimk,part,x1,x2AsDouble

OnErrorGoToErr_dPersent

lngCount=Nz(DCount("*",strNameTBL,strFilter),0)
IflngCount=0ThenDPersent=Null:ExitFunction

Setrst=NewADODB.Recordset
rst.Open"select"&strNameFields&"from"&strNameTBL&IIf(strFilter="","","where"&strFilter)&"orderby"&strNameFields,CurrentProject.Connection,adOpenKeyset,adLockReadOnly
IflngCount=1ThenDPersent=Nz(rst.Fields(0),0):Setrst=Nothing:ExitFunction

k=p*(lngCount-1)/100+1
If(k/Int(k))=0Or(k/Int(k))=1Then
rst.AbsolutePosition=CLng(k)
DPersent=Nz(rst.Fields(0),0)
Else
part=k-Int(k)
rst.AbsolutePosition=CLng(Int(k))
x1=Nz(rst.Fields(0),0)
rst.MoveNext
x2=Nz(rst.Fields(0),0)
DPersent=(1-part)*x1+part*x2
EndIf

Setrst=Nothing
Exit_dPersent:
ExitFunction

Err_dPersent:
SelectCaseErr.Number
CaseElse
MsgBox"("&Err.Number&")"&Err.Description&"dMedian"
ResumeExit_dPersent
EndSelect
EndFunction


     
 
 
  : 28.04.2006  

| | | | SILICON TAIGA | ISDEF | CD | | | | | | | |

: Silicon Taiga    
Rambler's Top100 Rambler's Top100