Function allname(tblName As String, fieldname As String, Optional criteria As String = "")
Dim D As Recordset
Dim sqlstr As String
Dim cristr As String
If criteria = "" Then
cristr = ""
Else
cristr = " where " & criteria
End If
sqlstr = "select " & fieldname & " from " & tblName & cristr & " GROUP BY " & fieldname
Set D = CurrentDb.OpenRecordset(sqlstr) '这一句提示有问题,
If Not D.EOF Then
D.MoveFirst
Do While Not D.EOF
If allname = "" Then
allname = D(0)
Else
allname = allname & "," & D(0)
End If
D.MoveNext
Loop
End If
End Function 作者: roych 时间: 2016-6-13 14:43
个人觉得复杂了。
建议用GetRows或者Getstring为佳: http://www.office-cn.net/thread-119067-1-1.html***********************************************************************************
Dim D As DAO.Recordset
'改成这样,那一句就没问题了。
Dim sqlstr As String
Dim cristr As String
If criteria = "" Then
cristr = ""
Else
cristr = " where " & criteria
End If
sqlstr = "select " & fieldname & " from " & tblName & cristr & " GROUP BY " & fieldname
Set D = CurrentDb.OpenRecordset(sqlstr) '这一句提示有问题。
***********************************************************************************