|
在 access的模块中建立一个自定义函数:
以下是网上下载的一段代码,但是放到access vba里的模块里面,一直提示“建立查询” SELECT没有结束语句,如何才能最后面的SELECT语句呢?
Public Function CombStr(TableName As String, FieldName As String, GroupField As String, GroupValue As String) As String
Dim ResultStr As String
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(" select " & FieldName & " from " & TableName & " where " & GroupField & "='" & GroupValue & "'")
If rs.RecordCount > 0 Then
Do While Not rs.EOF
ResultStr = ResultStr & "," & rs.Fields(0).Value
rs.MoveNext
Loop
End If
If ResultStr <> "" Then ResultStr = Mid(ResultStr, 2)
CombStr = ResultStr
End Function
建立查询:
SELECT T.comname, combstr("T","Name","comname",t.comname) AS CombName, combstr("T","ses","comname",t.comname) AS CombSex
FROM T
GROUP BY T.comname
|
|