Jonathan LaRosa wrote:
Sorry Salad, but I fail to see how your example is a dynamically
generated SQL statement.
Here's my full code (including the dynamic part):
------------------
sqlForReport = "SELECT [Transaction ID] FROM " & _
"[" & Me.RecordSource & "]"
If Not (IsNull(Me.Filter) Or Me.Filter = "") Then
sqlForReport = sqlForReport & " WHERE " & Me.Filter
End If
sqlString = "SELECT [Confirmation Sent?], [Date Confirmation] " & _
"FROM [Transaction / Billing Information Info] " & _
"WHERE (([Transaction ID]) In " & _
"( & sqlForReport & "));"
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset(sqlString, dbOpenDynaset)
-----------------
This code appears in a report. The variable sqlForReport basically
gives me a list of transaction ID's that the report is displaying. I
don't know this ahead of time - it depends on what critera, if any,
the user chooses to view the report with (which becomes the filter).
Forgive me if I'm missing something obvious here, but I don't see how
what you posted is analagous to this situation.
thanks,
jon
"What we have here...is a failure...to communicate"
Me. I'd debug.print your SQL. Then I'd copy the printed line to the
clipboard and paste into a SQL view window and run it. I'd probably
find your error there.
I provided you a Join method in the last response that will be much
faster than your subselect. Maybe you like subselects....if so, carry
on with that method.
Generally I would create a general query in the query builder, copy to
the clipboard the SQL command, and paste into a code window and modify
it and make is dynamic as I want.
Ahhhh...I see you aren't using a subselect anymore as in the original.
And it won't work. If you are going to use the IN, the format usually
looks something like
ID In (1,2,3)
and where you use
"WHERE (([Transaction ID]) In " & _
"( & sqlForReport & "));"
will never work as you are expecting the TXID to be found in
sqlforreport which is a record set, not a list.
Hopefully someone can tell you how to do this. I would re-read what I
provided you in this thread, since the answer to your problem is there.