2
可能重複:
running sql statement from excel vba附近有語法錯誤關鍵字 '選擇' 使用VBA
下面是造成問題的摘錄:
Dim myquery As String
Set cn = New ADODB.Connection
cn.Open ' Some connection that opens properly
myquery = "select * from batchinfo where datapath='" + dpath + "' and analystname='" + aname + "' and reportname='" + rname + "' and batchstate='" + bstate + "'"
' dpath, aname, rname, and bstate are declared earlier in the sub
rs.Open myquery, cn, adOpenKeyset, adLockOptimistic, adCmdTable
這裏是一個樣本運行時myquery字符串:
"select * from batchinfo where datapath='111119-0021_excel short summary_111122191339.xlsx'
and analystname='none' and reportname='none' and batchstate='none'"
然而,在這條線,代碼休息,給了一個錯誤
任何想法的人「關鍵字‘選擇’附近有語法錯誤」?
考慮使用連接運算符'&'而不是'+'。 – onedaywhen