【问题标题】:Getting the value not the ID获取值而不是 ID
【发布时间】:2010-06-29 20:21:20
【问题描述】:

我有一个表 tblInvestigators,其中包含一个查找字段以显示名称列表

一项资助可能有超过 1 名调查员。

我的项目的一个要求是在拨款详细信息旁边的一个单元格中列出所有研究人员,所以我有:

赠款 A |姓名 A、姓名 B、姓名 C 等等

我有一个 VBA 模块,将调查人员连接到 1 个单元格中,如下所示:

 'Concat Returns lists of items which are within a grouped field
 Public Function c(strID As String, strAddMe As String) As String
     Static prevID As String
     Static strFinal As String
     Static strLastAdded As String

If (strID = prevID And strAddMe <> strLastAdded) Then
          strFinal = strFinal & ", " & strAddMe
Else
          prevID = strID
          strLastAdded = strAddMe
          strFinal = strAddMe
End If
     c = strFinal

 End Function

以及调用它的访问查询(SQL):

SELECT g.grant_id, Max(c(g.grant_id,tblInvestigators.investigator)) AS Expr1
FROM tblGrants AS g LEFT JOIN tblInvestigators ON g.grant_id = tblInvestigators.grant_id
WHERE (((g.grant_id)=6))
GROUP BY g.grant_id;

当我运行它时,它返回一个逗号分隔的列表,但它是查找列 (tblInvestigators.investigator) 中的 ID 号列表,而不是名称。我怎样才能得到名字?

克里斯

【问题讨论】:

    标签: ms-access module field lookup


    【解决方案1】:

    使用查找字段绝不是一个好主意:http://www.mvps.org/access/lookupfields.htm

    它是在伪装获得你想要的结果的标准方式,即使用查询将ID连接到查找表并返回描述。

    看看这个Does MS access(2003) have anything comparable to Stored procedure. I want to run a complex query in MS acceess

    【讨论】:

    • 太好了,谢谢。我没有意识到查找字段是这样一个问题。我刚刚添加了一个数字字段,将其更新为查找值,删除了查找字段并重命名。我现在有一个存储了关系和 id 的常规查找表,实现了如上所述的连接功能,并使用 sql join 将我的数据与查找表连接起来,正如您所期望的那样谢谢!克里斯
    猜你喜欢
    • 2012-12-28
    • 1970-01-01
    • 2022-10-07
    • 2014-04-23
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多