|
以下是一个合并字段的自定义函数代码:
Public Function Concatenate(pstrSQL As String, Optional pstrDelim As String = "、") As String
Dim Rs As New ADODB.Recordset
Rs.Open pstrSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Dim strConcat As String 'Build SQLstring
With Rs
If Not .EOF Then
.MoveFirst
Do While Not .EOF
strConcat = strConcat & _
.Fields(0) & pstrDelim
.MoveNext
Loop
End If
.close
End With
Set Rs = Nothing
'Set db = Nothing
If Len(strConcat) > 0 Then
strConcat = Left(strConcat, Len(strConcat) - Len(pstrDelim))
End If
Concatenate = strConcat
End Function
以上代码用于一个基于表的查询就没问题,但用于基于查询的查询就会很慢,数据在1千条以上时要等上两三分钟,为什么呢?应作如何修改?请高人指点! |
|