I think the issue may be that Access doesn't know it's a pass-through query
until the Connect property gets set.
Try cheating:
strSQL = "EXEC IDX_TimeData " & "'" & txtFromDate & "', " & "'" &
txtToDate & "', " & param1 & ", " & param2 & ", " & param3 & ", " & param4
Set qdfPassthrough = db.CreateQueryDef("", "SELECT Field1 FROM
Table1")
With qdfPassthrough
.Connect = "Provider=ODBC;DSN=Finance"
.SQL = strSQL
.ODBCTimeout = 0
.ReturnsRecords = True
.Close
End With
Set qdfPassthrough = Nothing
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"rick" <(E-Mail Removed)> wrote in message
news:34E528D4-B5DC-44C2-B0ED-(E-Mail Removed)...
> David, I have no idea where those brackets came from. They aren't in my
> code:
>
> strSQL = "EXEC IDX_TimeData " & "'" & txtFromDate & "', " & "'" &
> txtToDate
> & "', " & param1 & ", " & param2 & ", " & param3 & ", " & param4
>
> It appears DAO is not recognizing the EXEC as a stored procedure. When I
> set up a dummy passthrough query in the database design and use it as my
> querydef to put the strSQL inside it, the query runs fine.
>
> "David H" wrote:
>
>> Side note, anytime I'm hardcoding a SQLStatment, I'll do a Debug.Print to
>> send it to the Immediate Window so I can actually see the statement if
>> any
>> issues come up.
>>
>> "rick" wrote:
>>
>> > I'm getting an error message when trying to run the following code to
>> > create
>> > a temporary querydef from a stored procedure called "IDX_TimeData" on
>> > our Sql
>> > Server:
>> >
>> > 'build a querydef for the passthrough sp w parameters using DAO
>> > Set db = CurrentDb
>> >
>> > strSQL = "EXEC IDX_TimeData " & "'" & txtFromDate & "', " & "'"
>> > &
>> > txtToDate & "', " & param1 & ", " & param2 & ", " & param3 & ", " &
>> > param4
>> >
>> > Set qdfPassthrough = db.CreateQueryDef("", strSQL)
>> > With qdfPassthrough
>> > .Connect = "Provider=ODBC;DSN=Finance"
>> > .ODBCTimeout = 0
>> > .ReturnsRecords = True
>> > .Close
>> > End With
>> > Set qdfPassthrough = Nothing
>> >
>> > At the CreateQueryDef statement, I get an error number 3139: Invalid
>> > SQL
>> > statement, expected DELETE, INSERT, UPDATE, SELECT or PROCEDURE.
>> >
>> > Apparently something is wrong with my SQL string.
>> >
>> > Help greatly appreciated.
>> > Rick