|
我在计算工资时出现了这样一个问题,在客户端输入数据后,经常无法计算,在服务器端则是有时可以有时不行。我的代码是
公用函数 好像strForm总报错,
Public Function GetValue(ID As Long, Num As Long)
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
strsql = "[EmployeeID]=" & Forms(strForm).[EmployeeID].Column(0)
sql = "SELECT DISTINCT TOP 2 EmployeeID, InUse, ValidDate, BasicSalary, Floating" _
& "Salary,TotalSalary FROM dbo.tblSalaryData WHERE (InUse <> 0) AND" & strsql & "" _
& "ORDER BY EmployeeID, ValidDate DESC"
Rs.Open sql, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
If Rs.RecordCount = 0 Then
'数据源不存在
Exit Function
End If
If Num = 1 Then
ReS = Rs("BasicSalary")
Else
If Num = 2 Then
If Rs.RecordCount = 1 Then
ReS = Rs("BasicSalary")
Else
Rs.MoveNext
End If
'在此加入代码,以保证在 RS 只有一条记录时不出错
ReS = Rs("BasicSalary")
End If
End If
GetValue = ReS
End Function
同理 GetValue1 = ReS
现有多个窗体需引用该值进行计算
C = GetValue([EmployeeID], 1)
D = GetValue1([EmployeeID], 1) |
|