|
一个不用循环实现的合并记录为字符串的函数,可在查询中调用
Public Function Dmerge(Exps As String, Domain As String, _
Optional Criteria As String, Optional Separator As String = ";") As String
'函数功能: 合并指定记录集指定字段值为一个字符串
'参数说明:
' expr : 要合并的字段
' domain : 来源表或查询
' criteria : 可选,限制记录的条件表达式
' Separator : 可选,合并记录的分隔符,默认为分号(;)
'
'调用示例1: Dmerge("姓名","人员表","性别='" & [性别] & "'",Chr(13) & Chr(10))
' 以上示例在查询中,使用了换行分隔符,返回换行显示的姓名
'调用示例2:Dmerge("产品名称","表1","订单ID=" & [订单ID])
'作 者: t小雨
'创建时间: 2009/11/25
On Error Resume Next
Dim rst As New ADODB.Recordset
Dim strSql As String
strSql = "Select " & Exps & " From " & Domain
If Criteria <> "" Then strSql = strSql & " Where " & Criteria
rst.Open strSql, CurrentProject.Connection, adOpenStatic, adLockReadOnly, adCmdText
If Not rst.EOF Then Dmerge = rst.GetString(adClipString, , , Separator)
rst.Close
Set rst = Nothing
End Function |
|