我正在尝试生成连接到我的访问数据库的Excel工作簿,并根据这些记录是否在两个字符串之间有一个Request_Date来从表中提取值。
如果我将字符串替换为实际日期,我写的代码工作正常但是当我尝试用字符串复制它时我得到上面的错误,接着是一个额外的错误'当对象时不允许操作已关闭'
以下是我正在使用的代码:
Public Sub RetrievePaymentMI()
Dim Date1 As Date
Dim Date2 As Date
Dim LastRow As Long
Dim MIdb As String
Dim MIpass As String
Sheets("Data").Range("B5:N1000").Clear
Date1 = Sheets("Summary").Cells(3, 4).Value
Date2 = Sheets("Summary").Cells(4, 4).Value
OpenDataBase MIdb, MIpass
sSQL = "SELECT Policy_Number, Customer_Name, Request_Date, Payment_Type, Dual_Amt, Int_Amt, DnI_Amt, Resolve, Payment_Method, Payment_Description, Further_Info, TL_Name, Status " & _
"FROM tblData " & _
"WHERE Request_Date > Date1 AND Request_Date < Date2 "
RetrieveDataBaseData (sSQL)
Sheets("Data").Cells(5, 2).CopyFromRecordset RecordSet
RecordSet.Close
MIDatabaseconnection.Close
MsgBox "Complete"
End Sub
我尝试了很多不同的方法,我已经宣布了Date1&amp; Date2作为字符串和日期,我已经更改了他们的名字。我试图将它们封装在##,&#34; &#34; &安培; &#39; &#39;
HELP !!