Access中定义GroupConcat函数时, .显示用户定义类型未定义,怎么修改?

定义的函数如下:
Public Function GroupConcat(sColumn As String, sTable As String, Optional sCriteria As String, Optional sDelimiter As String = ",")
On Error GoTo ErrHandler
Dim rs As New ADODB.Recordset
Dim sSQL As String
Dim sResult As String
sResult = ""
sSQL = "select " & sColumn & " from " & sTable
If sCriteria <> "" Then
sSQL = sSQL & " where " & sCriteria
End If
rs.Open sSQL, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
Do While Not rs.EOF
If sResult <> "" Then
sResult = sResult & sDelimiter
End If
sResult = sResult & rs.Fields(0).Value
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
GroupConcat = sResult
Exit Function
ErrHandler:
If rs.State <> adStateClosed Then
rs.Close
End If
Set rs = Nothing
GroupConcat = Err.Number & " : " & Err.Description
End Function

该函数可以实现多行合并为一行吗?

查看全部
jennyhappy1
jennyhappy1
2015/05/27 08:02
  • access
  • groupconcat
  • 点赞
  • 收藏
  • 回答
    私信

2个回复