Results 1 to 5 of 5
  1. #1
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126

    Query expression asking for an ID

    I am trying to add an expression in a query to determine the number of games teams are behind the leader.

    I have used the expression in a form with no problems but when I try to use it in a query I get prompted of the 'ID' and I am not sure how to write this.

    In a form =Max([W])-[W] returns a value for the number of games t team is behind from 0 for the leader on down the list, but I can not get it to work in a query.



    Code:
    Behind: Max([SportsMLBALCPlayoffQry].[W])-[W]
    .

    Where do I add the 'ID'?

    Jim O

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    before trying to answer your question, please provide the full sql to your query (in your query, go to the sql window and copy and paste the code). At the moment you have asked the equivalent of 'My car won't start, it's painted red, why?'

  3. #3
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    Thanks for your response,

    I can see the number of games a team is behind in the form but I would like to have that data in the query so I can access it from a list box generated from this query.

    Code:
    SELECT SportsMLBLeagueQry.ID, SportsMLBLeagueQry.Div, SportsMLBLeagueQry.Team, SportsMLBLeagueQry.W, SportsMLBLeagueQry.L, SportsMLBLeagueQry.League, SportsMLBLeagueQry.WinLoss, [W]+[L] AS GamesPlayed, SportsMLBLeagueQry.Updated, SportsMLBLeagueQry.NickName, DCount("*","SportsMLBALCPlayoffQry","WinLoss>" & [WinLoss])+1 AS Rank
    FROM SportsMLBLeagueQry
    WHERE (((SportsMLBLeagueQry.Div)="AL Central") AND ((SportsMLBLeagueQry.League)="AL"))
    ORDER BY SportsMLBLeagueQry.WinLoss DESC;
    Jim O

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    thanks - you'll either need to make the query a groupby query - click on the epsilon icon (totals) in the ribbon or use DMax in much the same way as you have used dcount. Something like

    Behind: DMax("[W]","[SportsMLBALCPlayoffQry]")-[W]

    not sure if you need a criteria to limit to the value in which case

    Behind: DMax("[W]","[SportsMLBALCPlayoffQry]","SportsMLBLeagueQry.Div='AL Central' AND SportsMLBLeagueQry.League='AL'")-[W]

  5. #5
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    Ajax,

    Thank you very much for your help. The first suggestion works great. I appreciate the time and patience with me.

    Jim O

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

Similar Threads

  1. Replies: 4
    Last Post: 05-03-2016, 01:51 PM
  2. query with expression
    By Andreabelzo in forum Queries
    Replies: 3
    Last Post: 08-17-2015, 03:14 PM
  3. Query IIF Expression Help
    By knowshowrosegrows in forum Queries
    Replies: 2
    Last Post: 08-28-2013, 02:16 PM
  4. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  5. Replies: 4
    Last Post: 10-26-2012, 12:49 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