[VBA ] 陣列索引超出範圍

作者: style90639 (school)   2014-07-25 01:02:32
我打算從EXCEL撈SQL的資料
但每次都會出現如題的訊息
是否能夠幫我看看到底哪裡的問題,
或者是否有驗證錯誤的方法@@
Sub logsheet()
Dim ad, start_time, End_Time, eq_period, critera1, critera2 As String
Application.ScreenUpdating = False
ad = InputBox("請輸入lotid")
ad = ucase(ad)
start_time = InputBox("請輸入start_time,例如:yyyy/mm/dd", , Date - 3)
end_time = InputBox("請輸入end_time,例如:yyyy/mm/dd", , Date + 1)
start_time = Format(start_time, "yyyy-mm-dd hh:mm:ss")
end_time = Format(end_time, "yyyy-mm-dd hh:mm:ss")
c1 = " WHERE AA1='" + ad + "' AND AA2='GG' AND AA4='W' AND AA3='T' AND
TIME >{ts '" + start_time + "'} AND TIME < {ts '" + end_time + "'}"
With Sheets("logsheet").Range("B1").QueryTable
.connection = "ODBC;DSN=****;UID=****;PWD=****;SERVER=****;"
.CommandText = "SELECT s.ad,s.st FROM AB1 " + c1
.Refresh BackgroundQuery:=False
End With
End Sub
作者: johnpage (johnpage)   2014-07-25 05:57:00
請用excel 2010試
作者: aspx   2014-07-28 12:00:00
可以先把SQL字串湊出來拿到SQL開發環境跑正不正常嗎?順便看看有幾列,善意提醒VBA的連接符號是&

Links booklink

Contact Us: admin [ a t ] ucptt.com