|
下面的自定义函数是网上老师以前提供的,作用是截取表中某列数据罗列至文本框中
用法在窗体文本框中:allname("表名","字段名","条件=条件")
以前(Access2003)好像可以用于查询表,但现在只能用于表,而不能用于查询表,不知是何原因?(07版)
请懂代码的老师指教!谢谢!
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
|
|