Results 1 to 7 of 7
  1. #1
    oleBucky's Avatar
    oleBucky is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2011
    Location
    Inside the Loop
    Posts
    100

    One works, the other doesn't. Why?

    In another thread the forum helped me come up with the following SQL to allow the selection for one fantasy team or all fantasy teams.

    Code:
    Select "*" AS HLBID, "(All HLB Teams)" AS HLBName
    FROM tblHLBTeams AS T1;
    
    UNION
    
    SELECT T1.HLBTeamID AS HLBID, T1.TeamName AS HLBName
    FROM tblHLBTeams AS T1
    ORDER BY HLBName;
    This worked as desired by adding this criteria to the row source for the object list box (listPlayers)
    Field: [HLBTeamID]
    Table: [tblPlayers]
    Criteria: Like [Forms]![frmCardByPosition]![listHLBTeam]

    I then went to test the second list box (for MLB Teams) independently by removing the above row source criteria. I am using the SQL below for the list box listMLBTeam then the following criteria to transfer the selections made in listMLBTeam to listPlayers
    Code:
    SELECT "*" AS MLBID, "(All MLB Teams)" as MLBTeam
    FROM tblMLBTeams AS T2;
    
    UNION
    
    SELECT T2.MLBTeamID AS MLBID, [T2.League] & " " & [T2.City] & " " & [T2.Club] AS MLBTeam
    FROM tblMLBTeams AS T2
    ORDER BY MLBTeam;
    Field: [MLBTeamID]
    Table: [tblPlayers]


    Criteria: Like [Forms]![frmCardByPosition]![listMLBTeam]

    The source list box, listMLBTeams, appears just as I would expect but the object list box (listPlayers) comes up blank. After much tweaking (brackets out and in, "T2" out and in, removing the concatenating calculated expression, etc., I am unable to make it work. This is the SQL for listPlayers.
    Code:
    SELECT tblPlayers.PlayerID, tblPlayers.NameLast, tblPlayers.NameFirst, tblPlayers.Year, tblMLBTeams.League, tblMLBTeams.City, tblMLBTeams.Club, tblPlayers.MLBTeamID
    FROM tblMLBTeams INNER JOIN tblPlayers ON tblMLBTeams.MLBTeamID = tblPlayers.MLBTeamID
    WHERE (((tblPlayers.MLBTeamID) Like [Forms]![frmCardByPosition]![listMLBTeam]))
    ORDER BY tblPlayers.NameLast, tblPlayers.NameFirst;
    Might the forum give this a look and help me find the mistake, big or small?

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Hi Bucky,

    Not sure if I'm following completely but I see 2 things that might be issues.

    1. Year is a reserved word in Access. You may have to use [Year].

    2. In your SQL you have used Like

    Code:
    ...
    WHERE (((tblPlayers.MLBTeamID) Like [Forms]![frmCardByPosition]!
    [listMLBTeam])) ...
    Try using = instead of Like and see if you get data

    Post back with results.

  3. #3
    oleBucky's Avatar
    oleBucky is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2011
    Location
    Inside the Loop
    Posts
    100
    Thanks, but no help with =. listPlayers comes back blank. BTW when I tested it with listHLBTeams, Like worked (returned the expected data for the selection in listHLBTeams).

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Ok,

    I'd try this

    SELECT tblPlayers.PlayerID, tblPlayers.NameLast, tblPlayers.NameFirst, tblPlayers.Year, tblMLBTeams.League, tblMLBTeams.City, tblMLBTeams.Club, tblPlayers.MLBTeamID
    FROM tblMLBTeams INNER JOIN tblPlayers ON tblMLBTeams.MLBTeamID = tblPlayers.MLBTeamID
    WHERE (((tblPlayers.MLBTeamID) Like [Forms]![frmCardByPosition]!
    [listMLBTeam]))
    ORDER BY tblPlayers.NameLast, tblPlayers.NameFirst;
    I would add this to your code
    Code:
    .....
     Like [Forms]![frmCardByPosition]!
    [listMLBTeam] & "*"))
    ....
    Can you try running this sql directly in the Query window

    SELECT tblPlayers.PlayerID, tblPlayers.NameLast, tblPlayers.NameFirst, tblPlayers.Year, tblMLBTeams.League, tblMLBTeams.City, tblMLBTeams.Club, tblPlayers.MLBTeamID
    FROM tblMLBTeams INNER JOIN tblPlayers ON tblMLBTeams.MLBTeamID = tblPlayers.MLBTeamID
    ORDER BY tblPlayers.NameLast, tblPlayers.NameFirst;
    I just removed the WHERE clause.
    I expect you should get back all the player data.


    Can you show the exact SQL you used in this?
    BTW when I tested it with listHLBTeams, Like worked (returned the expected data for the selection in listHLBTeams).

  5. #5
    oleBucky's Avatar
    oleBucky is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2011
    Location
    Inside the Loop
    Posts
    100
    Quote Originally Posted by orange View Post
    Can you show the exact SQL you used in this?
    Here's the SQL that works from listHLBTeam to listPlayers.
    Code:
    SELECT tblPlayers.PlayerID, tblPlayers.NameLast, tblPlayers.NameFirst, tblPlayers.Year, tblMLBTeams.League, tblMLBTeams.City, tblMLBTeams.Club, tblPlayers.HLBTeamID
    FROM tblMLBTeams INNER JOIN tblPlayers ON tblMLBTeams.MLBTeamID = tblPlayers.MLBTeamID
    WHERE (((tblPlayers.HLBTeamID) Like [Forms]![frmCardByPosition]![listHLBTeam]))
    ORDER BY tblPlayers.NameLast, tblPlayers.NameFirst;
    I just tested it again and all is working.

    I will try your suggestions with listMLBTeam and post back.
    Last edited by oleBucky; 05-08-2011 at 09:12 AM. Reason: Posted SQL from source control, not object control.

  6. #6
    oleBucky's Avatar
    oleBucky is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2011
    Location
    Inside the Loop
    Posts
    100
    I added the asterisk and changed the field name from "Year" to "Yr". With this code, listPlayers is no longer blank. However, the code returned all players regardless of the selection in listMLBTeams.

    Code:
    SELECT tblPlayers.PlayerID, tblPlayers.NameLast, tblPlayers.NameFirst, tblPlayers.Yr, tblMLBTeams.League, tblMLBTeams.City, tblMLBTeams.Club, tblPlayers.MLBTeamID
    FROM tblMLBTeams INNER JOIN tblPlayers ON tblMLBTeams.MLBTeamID = tblPlayers.MLBTeamID
    WHERE (((tblPlayers.MLBTeamID) Like [Forms]![frmCardByPosition]![listMLBTeam] & "*"))
    ORDER BY tblPlayers.NameLast, tblPlayers.NameFirst;
    I also ran the code with out the WHERE clause as you suggested in the Query window. It too came up with all the players.

  7. #7
    oleBucky's Avatar
    oleBucky is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2011
    Location
    Inside the Loop
    Posts
    100
    completely.

    I decided to run some text boxes to look at what was coming out of the list boxes in question. It was immediately apparent the listMLBTeams was not sending a value to my test text box. Upon review of ALL the properties on listMLBTeams, I had, at some point in this process, set the Multi Select property to Extended. I reset the property to None and all is well.

    Now all I have to do is try to integrate all my criteria list boxes into one result for my player list box. Wish me luck.

    Again, thanks for all the input along the way and regrets on the ridiculous oversight.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Can someone explain how this works?
    By daveofgv in forum Access
    Replies: 3
    Last Post: 04-23-2011, 09:59 AM
  2. db: some records works other not...
    By bobrock4 in forum Access
    Replies: 1
    Last Post: 12-16-2010, 09:17 AM
  3. Replies: 11
    Last Post: 04-04-2010, 07:42 AM
  4. Ensuring Everything Works...?
    By catat in forum Access
    Replies: 1
    Last Post: 03-31-2010, 01:44 PM
  5. Import from MS Works
    By jerald in forum Import/Export Data
    Replies: 0
    Last Post: 03-17-2009, 08:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums