2013-07-19 98 views
1

我想從函數調用中的表中引用特定字段。具體來說,我想打開一個可執行文件並從表中獲取路徑。 這裏,路徑是硬編碼:在VBA子程序中引用Microsoft Access 2010表值

Shell(「C:\ECLIPSE_CPP\eclipse.exe」) 

不過,我想存儲的路徑表內,並調用一個函數(也許Shell函數?),從該表中的路徑上。

這是我曾嘗試:

strSQL = 「SELECT Path FROM Paths WHERE Tool = 「」Eclipse」」;」 
    Shell(strSQL) 

的路徑表看起來像這樣:

 
    Tool | Path 
    ========|=============================
Eclipse | 「C:\ECLIPSE_CPP\eclipse.exe」

有誰知道的方式來引用VBA代碼此表中的值?

回答

2
strPath = DLookup("Path" , "Paths" , "Tool = 'Eclipse'") 
Shell(strPath) 

DLookup效率不高。您的目的可能沒有問題,但如果沒有,您可以使用recordset來檢索該值。

2
Dim dbs as DAO.Database 
Dim rs as DAO.Recordset 
Dim strpath as String 

Set dbs = CurrentDb 
Set rs = dbs.OpenRecordset("Select Path from Paths where Tool = 'Eclipse'") 

strpath = rs.Fields(0) 
    ' = rs!Path  alternative 
    '   = rs("Path") alternative 

Application.FollowHyperlink(strpath) 
+0

Upvote - 記錄集代碼的好答案,甚至還有一個'Application'函數。 – Smandoli

相關問題