Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

列合行函数修改

时 间:2011-06-01 00:00:00
作 者:一过客   ID:10671  城市:成都
摘 要:原函数在编号、项目缺损时会出现参数无效,加入“If Not rs.EOF Then”后避免了出错


正 文:

原函数在编号、项目缺损时会出现参数无效,加入“If Not rs.EOF Then”后避免了出错

Function DDSUM(tbname As String, fldname As String, fldIDname As String, StrID As String) As String
'示例:select  ID & " " & DDSUM("结果","项目","  ID ",[  ID ]) from公卫结果group by  ID

Dim rs As New ADODB.Recordset
Dim ssql As String
Dim i As Long
Dim s As String
ssql = "select " & fldname & " from " & tbname & " where Cstr(" & fldIDname & ")='" & StrID & "'"
rs.Open ssql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    If Not rs.EOF Then
        For i = 1 To rs.RecordCount
            DDSUM = DDSUM & rs.Fields(fldname).Value & " "
            rs.MoveNext
        Next
        DDSUM = Left(DDSUM, Len(DDSUM) - 1)
    End If
rs.Close
Set rs = Nothing
End Function



Access软件网官方交流QQ群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助