可能性の重複を使用して:
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