Full Version: Listboxes and queries displaying wrong information
UtterAccess Discussion Forums > Microsoft® Access > Access Q and A
Nside
I have two problems that have stumped me. You guys are pretty smart, please comment...

1)
SQL:
SELECT tblVolunteers.VolID, [LName] & ', ' & [FName] AS Name, IIf([MailTo]=1,[City],[MCity]) AS CurrentCity, IIf([MailTo]=1,[tblStates].[Abrv],[tblStates_1].[Abrv]) AS CurrentState
FROM (tblVolunteers LEFT JOIN tblStates ON tblVolunteers.StateID = tblStates.StateID) LEFT JOIN tblStates AS tblStates_1 ON tblVolunteers.MStateID = tblStates_1.StateID
WHERE (((tblVolunteers.TypeID)=2) AND ((tblVolunteers.Archive)=0))
ORDER BY [LName] & ', ' & [FName];

This is the SQL for the rowsource of a listbox. This listbox has four columns, the first (VolID) is hidden, the second (Name), the third is city and the fourth is state. Some of our volunteers have a primary address and a secondary address. The MailTo field determines which address to use. When I do the datasheet view this query works perfectly...it lists the volunteers by "LName, FName" and lists their city and state according to their MailTo field. However, when I click on the listbox, it displays the volunteer's primary address even if their MailTo address is their secondary address. What's the deal? Any suggestions?

2)
SQL:
SELECT tblVolunteers.FName, tblVolunteers.LName, [Lname] & ", " & [Fname] AS Name
FROM tblVolunteers;

Similar problem as above. Certain records in our tblVolunteers are not displayed correctly when queried. When I view the datasheet view, on certain records the FName is displayed correctly, the LName is displayed correctly but the Name (LName, FName) is not being displayed correctly. Sometimes it will display only the LName without the ", FName ". Any ideas?

Sorry if this is confusing! I look forward to your comments!
Dan
ViagraFalls
My guess towards the first question is that seeing you're calling the query from a form, that's where access looks for MailTo. Seeing you don't specify the MailTo field other than in the IIF statement, this might throw Access off and have it always set Mailto to the primary address. You can try making sure you include the tablename to the MailTo field as well. (Not tested; just brainstorming. It's good practise anyway to always include the tablename, as to clarify where the data is coming from).

As for the second problem, I have no idea. I created a similar query on a system table, and that works just fine.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.