我想從用戶被提供在Excel工作表,所述起始和結束日期自動執行的開始和結束日期。下面是我到目前爲止的代碼:我希望自動從用戶被提供在Excel工作表
Sub Button1_Click() ; formatted
Dim startDate As Date
Dim endDate As Date
startDate = Worksheets("sheet1").Range("B4").Value
endDate = Worksheets("sheet1").Range("B6").Value
dbConnectStr = "Provider=xxdose;User Id=" & Uname
dbConnectStr1 = "Provider=xxdose;User Id=xxtrece ;Data Source=" & DSN
Worksheets("WorkFlow").Activate
ActiveSheet.Range("B4:C30000").Clear
'Set and Execute SQL Command
Set Sql.ActiveConnection = objmyconn
Sql.CommandText = "select system_date from syit_act_log where system_date between`enter code here` 'startDate' AND 'endDate' and action_id = 15 and log_desc not like '%svc_openlink_p%' order by system_date"
Sql.CommandType = adCmdText
Sql.Execute
Next
ActiveSheet.Range("B5").CopyFromRecordset (ds)
ActiveSheet.Range("A1").Select
End Sub
嘗試使用#圍繞它們格式化開始日期和結束日期。像「... System_date> =#」&StartDate&「#...」 –
我會把這個SQL查詢嗎?你是說像這樣:...之間 'System_date> =# 「&的startDate&AND' System_date> =#」 &結束日期及.... @RyanWildry –
你需要逃避你的變量爲你的SQL語句。 –