StartDate3 = Format(StartDate1, "dd/mm/yyyy hh:mm:ss")
EndDate3 = Format(EndDate1, "dd/mm/yyyy hh:mm:ss")
Dim cn As Object
Dim rs As ADODB.Recordset
Set cn = CreateObject("ADODB.Connection")
Set sqlConnect = New ADODB.Connection
Set rs = New ADODB.Recordset
sqlConnect.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="SOURCE";Persist Security Info=False;"
cn.Open sqlConnect
rs.ActiveConnection = cn
Sql = "SELECT * FROM [tblDatabase] WHERE [Meldt Dato] BETWEEN '" & StartDate3 & "' AND '" & EndDate3 & "';"
rs.Open Sql, cn, adOpenDynamic, adLockOptimistic
With rs
End With
它给我一个挪威语的错误,所以我不确定它会用英语说什么,但大致翻译它说"表达式中数据类型之间没有协议"或类似的东西:p
答案 0 :(得分:1)
您不需要此00:00:00
,哈希#
标记是关键。
答案 1 :(得分:0)
将代码更改为:
Sql = "SELECT * FROM [tblDatabase] WHERE [Meldt Dato] BETWEEN #" & StartDate1 & " # AND # " & EndDate1 & " #;"
这似乎就是这样做的!