tags:

views:

136

answers:

2

I am writing an Access 2003 form to get a listing of all people currently in a facility.

I have a saved query that gives me the results I expect when I look at the Datasheet view (listing of all names with the associated account number).

If I use that same saved query as my ListBox.RowSource, I get the same list of names, but only ~10% of the names listed have an account number. tblOne.ACCOUNT is guaranteed to not be null so I'm not sure how those empty results come up.

SELECT tblOne.NAME, tblOne.ACCOUNT
FROM   tblOne INNER JOIN tblTwo ON
       tblOne.ID = tblTwo.ID
WHERE  tblOne.ENTER_DT >= (Date()-7)
  AND  tblTwo.EXIT_DT Is Null
ORDER BY tblOne.NAME

Both of the tables are linked tables. The listbox has two columns. I can not explain why a saved query is giving me different results depending on if I look at it using the Datasheet view or use it as the RowSource of a ListBox.

The errors started to come into play when I added the INNER JOIN. But it still works correctly in the Datasheet view with the JOIN statement.

A: 

That's mysterious. But there are some obvious trouble shooting steps. What do you get using this as a basis?

SELECT tblOne.NAME, tblOne.ACCOUNT FROM tblOne

Trouble shooting often consists of "dumbing down" until you get something that seems to work, then incrementally adding complexity until you have your desired result. Somewhere on that path, you fix your error.

Smandoli
I have tried that before and it did work correctly. Errors started to happen when I added in the join. Is there a problem with using joins on linked tables? I made sure that the PK for the linked tables were the same as the table they are linked to.tblOne.ACCOUNT is also guaranteed to never be empty which is another reason why this is so odd.I edited the original post to be a bit more clear.
Using joins on linked tables: not a problem assuming all the links go to MS Access docs (Microsoft worked very hard on that one). If you can isolate it to the JOIN, keep hammering on that -- leave off all the WHERE and ORDER while hammering. Try JOIN not INNER JOIN. It makes sense that the ListBox ControlSource is more touchy then query view! You may end up resorting to a work-around.
Smandoli
BTW, about the WHERE clause: IsNull(EXIT_DT) may serve you better.
Smandoli
Thanks for the advice. I will have to work on that later. I do have a work-around, but I don't like it (getting the result set of the same query, then looping through each row and adding it to the ListBox as comma delimitted values).
The database I am hooking to is not a MS Access doc. It is not even an off-the-shelf database, so that may also be causing the issue. I am using the latest ODBC driver from the vendor in order to connect to it through Access.
ODBC might be worth a tag here. You can make stubby replicas of the two tables in local native Access, to see how they function. To get better counsel here, (A) post the code that sets rowsource and (B) talk about the back-end sources.
Smandoli
A: 

What happens if you use SELECT DISTINCT in both your Listbox and Query ? Does that help getting the same expected result ?

iDevlop