Select specific dated recordset

rickyfong

Registered User.
Local time
Today, 12:34
Joined
Nov 25, 2010
Messages
199
Set TRANS1 = db.OpenRecordset("SELECT * FROM MASTER WHERE DatePart("yyyy", TRANS1![CDATE]) = " & 2014, dbOpenDynaset)

In the above recordset selection, the ACCESS seems do not allow to have the DATEPART("YYYY") function in the syntax. As CDATE is a table field with date/time data type. Just want to know, how to do this kind of date selection. My purpose is to select all records according to a specific date to the TRANS1 recordset. Thanks a lot!!
 
Nested quotes are the problem. Use single quotes inside the double quoted section

Code:
Set TRANS1 = db.OpenRecordset("SELECT * FROM MASTER WHERE DatePart('yyyy', TRANS1![CDATE]) = " & 2014, dbOpenDynaset)

BTW CDate is a VBA function and best avoided as an object name.
 

Users who are viewing this thread

Back
Top Bottom