CTE Passthrough query giving error(3129) (1 Viewer)

Kingz

Member
Local time
Today, 01:55
Joined
Mar 19, 2024
Messages
38
Hi guys,
I've got a complicated CTE query (strQuery) which works as a passthrough query, so I needed to dynamically set some dates in it, and execute it via VBA. I get an error 3129, meaning that it expects, instead of "with", delete, insert, select, or such likes..
Here is the relevant code:
Dim dbs as database
Dim rs as dao.recordset


Set rs = currentdb.openrecordset (
StrQuery, dbopendynaset, dbSQLPassThrough)


Thanks
 

Minty

AWF VIP
Local time
Today, 00:55
Joined
Jul 26, 2013
Messages
10,371
You need to open it using the correct parameters, so you need to set the query def to return records.
Something like (untested)

SQL:
strQuery = "; With myCTE as ( blah blah blah)"
Set qDef = db.QueryDefs("qPT_Generic")
qDef.SQL = strQuery
qDef.ReturnsRecords = True
qDef.Close

set rs = Currentdb.OpenRecordset("qpt_Generic", dbOpenSnapshot)

This relies in you setting up a PT query called qpt_Generic that you utilise for this purpose.
 

Kingz

Member
Local time
Today, 01:55
Joined
Mar 19, 2024
Messages
38
You need to open it using the correct parameters, so you need to set the query def to return records.
Something like (untested)

SQL:
strQuery = "; With myCTE as ( blah blah blah)"
Set qDef = db.QueryDefs("qPT_Generic")
qDef.SQL = strQuery
qDef.ReturnsRecords = True
qDef.Close

set rs = Currentdb.OpenRecordset("qpt_Generic", dbOpenSnapshot)

This relies in you setting up a PT query called qpt_Generic that you utilise for this purpose.
Fantastic!! Thanks for that!
 

Users who are viewing this thread

Top Bottom