1
下面的代碼給出了一個錯誤和「否爲一個或多個參數的給定值」停止在行:rs.open QRY,CNExcel的VBA到MS Access - 查詢沒有得到執行
然而,如果其他QRY當前被註釋掉(SELECT * FROM CallData)被執行,然後代碼運行沒有任何問題。
我需要做些什麼修改才能讓代碼正確運行GROUP BY查詢?
Dim cn As Object Dim rs As Object Dim qry As String Dim Insertws As Worksheet Dim strConnectString As String Set Insertws = ThisWorkbook.Sheets("temp") Insertws.Cells.Clear strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\corpfiler09\26663700_N01\NewAstt\ASTT.MDB;Jet OLEDB:Database Password=test;" 'Connect Database; insert a new table Set cn = CreateObject("ADODB.Connection") Set rs = CreateObject("ADODB.Recordset") 'qry = "SELECT * FROM CallData;" qry = "SELECT Bank, Count(Bank) from CallData where TicketDate = Date GROUP BY Bank"cn.Open strConnectString rs.Open qry, cn
訪問時認爲一個參數是必須的,它實際上意味着它不能識別的關鍵字。如果Date是一個函數,你可能需要使用它:'Date()'(按照Jens的答案) – 2015-02-23 11:03:02