Results 1 to 7 of 7
  1. #1
    ItsRoland is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    111

    Expressions and Functions in Query Not Working

    I'm trying to build a query that contains an overview of the rest of the database, as in has all the important information in it.



    I need to display the max value for "impact" in the table "tImpact". I set up an expression as follows:

    Code:
    DMax([tImpact].[impact], [tImpact], [tImpact].[scenarioID] = [tScenarios].[scenarioID])
    Please note that [tScenarios].[scenarioID] is also in the query. For some reason, when I go to datasheet view, it prompts me for a parameter for [tImpact]. This expression is the only place that the table [tImpact] appears in the query.

    I'm also using a function to get a value for the query. The function calculates how much the Impact is reduced, which I already know is calculating properly, as its being used in a few other places as well. The final result is stored in a variable, "Ireduc", and I then set that to the function name.

    Code:
    'Calculations...
    
    impactReduction = Ireduc
    
    Exit Function
    
    End Function
    I have another function giving values to the query that's set up the same way, and that one is working properly, but this one is displaying a 0 for every record. If it makes a difference, the working functions returns a string, and the one in question returns a double.

    Let me know if any additional information is needed.

    Any help is greatly appreciated!

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Your syntax is wrong have a look here http://access.mvps.org/access/general/gen0018.htm

    Something like

    Code:
    DMax("impact", "tImpact", "[scenarioID] = [tScenarios].[scenarioID]")
    However as this is in a table you can join to you should really use a join or a sub-query, as it's a lot more efficient.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    ItsRoland is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    111
    Ah, didn't realize I needed quotes when using it in a query expression.


    After making the change, it's now telling me it couldn't find the name: 'tScenarios.scenarioID'. I've checked to make sure it's spelled correctly, so I can confirm that is not the issue.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    So have you included tScenarios in your query? It will have to be for the query to use it's value.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    ItsRoland is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    111
    Yes, the table being referenced is included in the query.

  6. #6
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You may need to concatenate the string - I hardly ever use Domain functions in queries try;

    Code:
    DMax("impact", "tImpact", "[scenarioID] = " & [tScenarios].[scenarioID] & "")
    This assumes ScenarioID is a number field , if not add single quotes around it ;
    Code:
    DMax("impact", "tImpact", "[scenarioID] = '" & [tScenarios].[scenarioID] & "'")
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    ItsRoland is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    111
    That fixed the issue with the expression, thank you!


    Now I just need to figure out why the function isn't working properly.

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

Similar Threads

  1. Replies: 8
    Last Post: 01-03-2017, 12:37 PM
  2. Replies: 8
    Last Post: 03-26-2014, 02:23 PM
  3. Replies: 16
    Last Post: 01-31-2014, 07:50 PM
  4. expressions in textboxes not working
    By funi.t in forum Forms
    Replies: 4
    Last Post: 01-30-2012, 02:12 AM
  5. nested functions not working in 2010?
    By Gdm in forum Queries
    Replies: 2
    Last Post: 08-02-2010, 08:02 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