2010-06-29 61 views
1

我有一个表tblInvestigators其中包含一个查找字段来显示名称列表获取值不是ID

一个授权可能有多个调查员。

我的项目的要求是列出所有调查人员旁边的补助细节的单细胞,所以我有:

格兰特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号列表而不是名称。我怎样才能得到名字?

克里斯

回答

2

这是从来没有使用查找领域是一个好主意: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

+0

太好了,谢谢。我没有意识到查询字段是这样一个问题。 我刚刚添加了一个数字字段,将其更新为查找值,删除了查找字段并重命名。 我现在有一个关系和id存储的常规查找表,实现了上面的连接函数,并使用sql连接来加入我的数据与查找表,如你所愿 谢谢! Chris – Chris 2010-06-30 21:01:45