sal21
PlatinumLounger
Posts: 4355 Joined: 26 Apr 2010, 17:36
Post
by sal21 » 19 May 2010, 12:47
Code here...
Code: Select all
DATA_ACCENSIONE = DateAdd("D", -14, Date)
Set CMD = New ADODB.Command
SQL = "SELECT * from DBO_CC_DAILY WHERE [DATA_ACC] >= #" & Format(DATA_ACCENSIONE, "mm/dd/yyyy") & _
"# AND TIPO_DATO='" & TEST_COUNT & "'"
With CMD
.CommandTimeout = 0
.CommandText = SQL
.ActiveConnection = OCONN
.CommandType = adCmdText
Set OCONN_RS = .Execute
Set CMD = Nothing
End With
HansV
Administrator
Posts: 78493 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 19 May 2010, 13:00
You don't specify any field(s) after SELECT.
You changed the code while I posted a reply!
Best wishes,
Hans
HansV
Administrator
Posts: 78493 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 19 May 2010, 13:05
Please insert the following line below the instruction SQL = ...:
Debug.Print SQL
When you run the code, the SQL string will be written to the Immediate window. Please copy this string and paste it into a reply.
Best wishes,
Hans
sal21
PlatinumLounger
Posts: 4355 Joined: 26 Apr 2010, 17:36
Post
by sal21 » 19 May 2010, 13:10
HansV wrote: Please insert the following line below the instruction SQL = ...:
Debug.Print SQL
When you run the code, the SQL string will be written to the Immediate window. Please copy this string and paste it into a reply.
Immediate window return:
SELECT * from DBO_CC_DAILY WHERE [DATA_ACC] >= #05/05/2010# AND TIPO_DATO='00'
note:
tipo_dato is formatted TEXT in table field
HansV
Administrator
Posts: 78493 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 19 May 2010, 13:16
The SQL looks OK. But since it looks like you're working with a SQL Server table, try this:
Code: Select all
SQL = "SELECT * from DBO_CC_DAILY WHERE [DATA_ACC] >= '" & Format(DATA_ACCENSIONE, "mm/dd/yyyy") & _
"' AND TIPO_DATO='" & TEST_COUNT & "'"
Best wishes,
Hans
sal21
PlatinumLounger
Posts: 4355 Joined: 26 Apr 2010, 17:36
Post
by sal21 » 20 May 2010, 06:14
HansV wrote: The SQL looks OK. But since it looks like you're working with a SQL Server table, try this:
Code: Select all
SQL = "SELECT * from DBO_CC_DAILY WHERE [DATA_ACC] >= '" & Format(DATA_ACCENSIONE, "mm/dd/yyyy") & _
"' AND TIPO_DATO='" & TEST_COUNT & "'"
Tks. work now!
Charlotte
Her Majesty
Posts: 499 Joined: 19 Jan 2010, 07:13
Post
by Charlotte » 20 May 2010, 16:41
Just to clarify this, Access SQL and the SQL used by SQL Server use different characters to delimit dates, so the same SQL that works in Access may not work in SQL Server and vice versa.
Charlotte
Carol W.
3StarLounger
Posts: 390 Joined: 26 Jan 2010, 16:02
Location: Las Vegas, NV
Post
by Carol W. » 20 May 2010, 17:00
Charlotte,
Thanks for clarifying this.
I was just about to post a question on this. I know that Access uses the # as a date delimiter. I now see that SQL Server uses a ' as a date delimiter.
Carol W.