Crosstab Query, Listbox Rowsource

D

Dan McClelland

True or false: A saved crosstab query can be used as the
rowsource of a listbox, while a transform SQL statement
cannot.

Using Access XP. Trying to generate an SQL string
dynamically, then populate a listbox using that string.
Works fine unless the SQL string contains TRANSFORM.
However, setting the rowsource of the listbox to a saved
crosstab query works fine.

Specifics: User clicks on a football player's name in
listbox #1. The OnClick event fires, the PlayerID is
stored in a variable, and the rowsource of listbox #2 is
set to an SQL statement. (It is more complex than this,
which is why I'm not using a parameterized saved query.)

If I use a simple SQL statement like this, it works:
lstStats.RowSource = "SELECT PassingTDs FROM
tblPlayerStats WHERE (PlayerNo = " & lngPlayerID & ");"

However, as soon as I use a crosstab query SQL statement,
it does nothing, like this:
lstStats.RowSource = "TRANSFORM Sum(PassingTDs) SELECT
tblPlayerStats.StatYear FROM tblPlayerStats WHERE
(PlayerID = " & lngPlayerID & ") GROUP BY StatYear PIVOT
tblPlayerStats.StatType;"

If I take the above Transform statement and save it, then
use that persisted query as the rowsource (without the
concatenated variable of course), it works fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top