|
回复 zhuyiwen 的帖子
我也做了一个DCountact
- Public Function DContact(expr As String, domain As String, grpFld As String, grpValue As Variant, Optional sp As String = ",") As String
- Dim SQL As String
- Dim vType As String
- vType = TypeName(grpValue)
-
- If vType = "String" Or vType = "Date" Then
- SQL = "SELECT " & expr & " FROM " & domain & " WHERE " & grpFld & " = '" & grpValue & "'"
- Else
- SQL = "SELECT " & expr & " FROM " & domain & " WHERE " & grpFld & " = " & grpValue
- End If
-
- Dim rs As Recordset
- Set rs = CurrentDb().OpenRecordset(SQL)
-
- Dim s As String
- Dim i As Long, n As Long, c As Long
-
- n = rs.Fields.Count
- Do While Not rs.EOF()
- For i = 0 To n - 1
- If c = 0 Then
- s = rs(i)
- Else
- s = s & sp & rs(i)
- End If
- c = c + 1
- Next
- rs.MoveNext
- Loop
- rs.Close
- Set rs = Nothing
-
- DContact = s
- End Function
复制代码
假设把你的数据存放在 表1 中,则做如下查询:
- SELECT DContact('ID','表1','货名',货名) AS ID, DContact('订单','表1','货名',货名) AS 订单, 货名
- FROM (SELECT DISTINCT 货名 FROM 表1) AS A;
复制代码
可得如下结果:
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|