Results 1 to 5 of 5
  1. #1
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501

    Dmax not returning latest value for text field

    I am using dmax to get the latest value from a table using two criteria. It works fine for the dates but does not work on the text field. The fields I have are id, customername, name, begindate, enddate (not the real field names). So when I use the dmax for the begindate and enddate it works fine, however, it does not work for name.

    What I want to be able to do is use DMax for the id field but return the customername, not the id.



    Is this possible

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Should be. As always, post what you tried. For anything more than a few lines of code, best to use code tags (# on thread toolbar).
    Your issue is likely incorrect concatenation, or not encasing text values in quotes (single are easiest) or both.

    EDIT - BTW, Max is not necessarily what you consider to be last or max, especially if you're trying to get either from a text field.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501
    I am using

    Code:
    =DMax("customername","CustomerAssignments","CarNumber = " & [Forms]![f_EMEUpdates]![CarNumber] & " And CarInitials ='" & [Forms]![f_EMEUpdates]![CarInitials] & "'")
    I also use

    Code:
    =DMax("customerbegin","CustomerAssignments","CarNumber = " & [Forms]![f_EMEUpdates]![CarNumber] & " And CarInitials ='" & [Forms]![f_EMEUpdates]![CarInitials] & "'")
    And that one works fine I think because it is a date. However, as you mentioned using a Dmax for text will yield different results, I am not sure what it considers the max. That is why I want to look up the most recent ID but return the text value in the customer field of that record. Dmax and Dlookup both only look up the max of the field you put in the first criteria.

    What I need to be able to do is look up the Max ID for records with the current carnumber and car initials but return the customername that is in that record.

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    What I want to be able to do is use DMax for the id field...
    No idea what this is; an autonumber field?
    maybe

    Code:
    DLookup("customername","CustomerAssignments","CarNumber = " & DMax('yourField','yourDomain'))
    or
    DLookup("customername","CustomerAssignments","CarNumber = " & Max(yourNumberField))
    EDIT - to answer your other question, max of a text field is simply alphabetically - assuming the comparison is not binary. If so, case matters; e.g. A < a.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Does this work?

    =Dlookup("CustomerName","CustomerAssignments","ID = " & DMax("ID","CustomerAssignments","CarNumber = " & [Forms]![f_EMEUpdates]![CarNumber] & " And CarInitials ='" & [Forms]![f_EMEUpdates]![CarInitials] & "'"))
    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 ↓↓

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

Similar Threads

  1. Replies: 13
    Last Post: 04-12-2017, 08:11 AM
  2. Replies: 3
    Last Post: 03-17-2017, 02:14 AM
  3. Replies: 8
    Last Post: 01-10-2016, 11:51 AM
  4. DMax returning Null
    By Markb384 in forum Access
    Replies: 1
    Last Post: 05-01-2014, 09:11 AM
  5. DMax returning wrong value
    By nedbenj in forum Access
    Replies: 7
    Last Post: 10-24-2007, 10:30 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