tags:

views:

226

answers:

1

the row source for a listbox looks like this:

SELECT users.id, users.first, users.last, chavrusas.luser_type AS user_type, chavrusas.id, users.title, users.city, users.state, users.home_phone, users.email  FROM Users INNER JOIN chavrusas ON Users.id=chavrusas.luser_id  WHERE ((chavrusas.ruser_id)=id_txt and chavrusas.ended=false) AND (chavrusas.luser_type)<>(chavrusas.ruser_type) AND NOT ((chavrusas.luser_type)='teacher' AND (chavrusas.ruser_type)='student') AND NOT ((chavrusas.ruser_type)='teacher' AND (chavrusas.luser_type)='student'); UNION SELECT users.id, users.first, users.last, chavrusas.ruser_type AS user_type, chavrusas.id, users.title, users.city, users.state, users.home_phone, users.email  FROM Users INNER JOIN chavrusas ON Users.id=chavrusas.ruser_id  WHERE ((chavrusas.luser_id)=id_txt and chavrusas.ended=false) AND (chavrusas.luser_type)<>(chavrusas.ruser_type) AND NOT ((chavrusas.luser_type)='teacher' AND (chavrusas.ruser_type)='student') AND NOT ((chavrusas.ruser_type)='teacher' AND (chavrusas.luser_type)='student')
ORDER BY 4;

for some reason, when there are more than just a few items that this statement returns, the listbox will display null values!! but if this statement returns 2-3 items, it will display them no problem.

+3  A: 

1) Does the query work when you run it in the query designer?

2) Are the number of fields in the query the same number as is in the listbox Column Count property?

3) What is the 4 in "ORDER BY 4"? 4 should be a field name such as users.last or user_type.

4) First and Last are the names of functions used in queries. So this will likely cause you problems in the future if it isn't already. Put square brackets around the field names or use different field names. Also see Tony's Table and Field Naming Conventions

Tony Toews
1. i will get back to you on this, 2. since it is correctly returning a few records, do you think this would still be an issue? 3. i changed to users.last and it gave the same result. 4. i am using these in the same way in other examples and they work fine
I__
2. I've had wierdnesses happen in the past when the number of columns in the query didn't match the column count. Granted this was ten years ago and I haven't seen the problem since. OTOH I may be a lot more careful since then. <smile> It also only takes a minute or so to check by counting the number of columns in the query datasheet view. 3. Interesting the use of 4 in the ORDER BY then. I've never seen that before but it's not in Access help but would appear to work.
Tony Toews
hey tony thank u for your response. can you please elaborate on how i can check for #2?
I__
2. view the query in datasheet view so you can see the data. Then count the columns. A lot easier than trying to figure out the number of columns by reviewing the commas in the field list in the raw SQL statements.
Tony Toews
done i set the count prop exactly the same and still doesnt work
I__
Using the ordinal number in the ORDER BY is useful for situations when the SELECT statements in your UNION don't have the same names, or when some columns are based on expressions instead of field names. I just ran into this last week where there was no way to sort a UNIONed result except by ordinal number, precisely because the fields to be sorted by in the first SELECT were based on hardwired values, and the second on expressions.
David-W-Fenton