自定义函数计算提成
点击下载此附件
Function TCJS(ByVal GoodsName As String, ByVal Model As String, ByVal Price As Double) As Double
On Error Resume Next
Dim rst1 As New ADODB.Recordset, rst2 As New ADODB.Recordset
Dim i As Long
Dim FieldName As String
Dim cSQL As String
rst1.Open "提成等级表", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rst1.MoveFirst
For i = 0 To rst1.Fields.Count - 1
If rst1.Fields(i).Name = Model Then
FieldName = rst1.Fields(i).Name
End If
Next
cSQL = "SELECT 名称,百分点,[" & FieldName & "] from 提成等级表 WHERE 名称='" & GoodsName & "' ORDER BY 百分点"
rst2.Open cSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If DMin("[" & FieldName & "]", "提成等级表", "名称='" & GoodsName & "'") > Price Then
TCJS = 0.01
ElseIf DMax("[" & FieldName & "]", "提成等级表", "名称='" & GoodsName & "'") <= Price Then
rst2.MoveLast
TCJS = rst2.Fields(1).Value
Else
rst2.MoveFirst
Do Until rst2.EOF
If rst2.Fields(2).Value > Price Then
rst2.MovePrevious
TCJS = rst2.Fields(1).Value
Exit Do
End If
rst2.MoveNext
Loop
End If
rst1.Close: Set rst1 = Nothing
rst2.Close: Set rst2 = Nothing
End Function