Thomas
Thomas

Reputation: 305

ADODB SQL string gives me an error

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

It gives me an error in Norwegian, so I am not sure what it would say in english, but roughly translated it says "No agreement between datatypes in expression" or something like that :p

Upvotes: 0

Views: 324

Answers (2)

Thomas
Thomas

Reputation: 305

Changed code to:

Sql = "SELECT * FROM [tblDatabase] WHERE [Meldt Dato] BETWEEN #" & StartDate1 & " # AND # " & EndDate1 & " #;"

And that seemed to do it!

Upvotes: 0

KyloRen
KyloRen

Reputation: 2741

You don't need this 00:00:00, the hash # tags are the key.

Upvotes: 1

Related Questions