[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