litao 发表于:2013-10-21 08:13:43
格式比照:dloolup,dsum,dcount,dmin 函数
谢谢!
没有的,你内容里面的这些是access中的【域聚函数】,就那几个,你上网一搜就明白了
仿照系统函数:Dlookup,Dsum,Dcount,Dmin
写了一个函数:DUpdate
请高手指点,能否优化!
Private Const SQL分隔符 = ","
Public Function DUpdate(字段串 As String, 数值串 As String, 记录集 As String,Optional WHERE As String="") As String '返回SQL语句
DUpdate = ""
If 字段串 = "" Or 数值串 = "" Or 记录集 = "" Then Exit Function
On Error GoTo err
Dim 字段() As String, 数值() As String, STR As String
字段 = Split(字段串, SQL分隔符)
数值 = Split(数值串, SQL分隔符)
STR = ""
For i = LBound(字段, 1) To UBound(字段, 1)
If i > UBound(数值, 1) Then Exit For '字段串与数值串 个数不一致。
STR = "," & 字段(i) & "=" & 数值(i)
Next i
STR = "SET " & Mid(STR, 2) ' SET 子句
STR = "UPDATE " & 记录集 & " " & STR
If WHERE <> "" Then STR = STR & " WHERE " & WHERE '有WHERE语句!
Debug.Print STR 'SQL语句!
DoCmd.SetWarnings False '关闭警告提示
DoCmd.RunSQL STR
DoCmd.SetWarnings True '打开警告提示
DUpdate = STR
Exit Function
err:
MsgBox Error$
End Function
总记录:2篇 页次:1/1 9 1 :