我有下面的代碼,但它不工作。它給了我錯誤:編譯錯誤,一個函數或變量是預期的。VBA上的SQL:編譯錯誤,函數或變量是預期的
我想錯誤是在Database.Execute方法,但我沒有提供解決方案。
Sub ChavesMontante()
Dim dbschaves As Database
Dim rschaves As DAO.Recordset
Dim tipodechave As String
Dim SQLCMD As String
Dim chave As String
Set dbschaves = CurrentDb
chave = "BED20777"
SQLCMD =
"(SELECT us.instalacao, ch.bloco, us.tipounidade " & _
"FROM (SELECT useccionadora, bloco " & _
"FROM sgdprd.redeprimaria rp " & _
"WHERE rp.useccionadora IS NOT NULL " & _
"CONNECT BY rp.nox = PRIOR rp.fontex AND rp.noy = PRIOR rp.fontey " & _
"START WITH rp.useccionadora = '" & chave & "') ch " & _
"INNER JOIN sgdprd.useccionadora us ON ch.useccionadora= us.instalacao) "
Debug.Print SQLCMD
Set rschaves = dbschaves.Execute(SQLCMD)
End Sub
Excel的VBA模型中沒有名爲'Database'的對象。 – cyboashu
我在訪問。對不起,我應該發佈。 –
您是否嘗試過'SQLCMD =「(SELECT us.instalacao,ch.bloco,us.tipounidade &&'' ...? – yacc