2010-06-29 59 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