Results 1 to 2 of 2
  1. #1
    Markb384 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    44

    DMax returning Null

    Hi guys and gals

    I have some code that appears to have broken. Fundamentally, I want to return a date value from a table in which it is the newest date that fulfils some criteria. As far as I am aware, it looks perfectly good, yet it is returning a null value.

    My table is structured as below...
    Equipment ID Survey Date Norm Baseline Norm Field Size Norm Groups Others....
    ID.A 1/5/2014 No 40 12
    ID.B 1/4/2014 Yes 40 11
    ID.A 1/3/2014 Yes 40 12
    ID.A 1/2/2014 No 40 12
    ID.A 1/1/2014 Yes 40 12

    and if the user selects the 1/5/2014 for ID.A, I want to return 1/3/14. If the user selects 1/2/14, 1/1/2014 is returned. I have some other code which catches if the user selects a date with Yes for Norm Baseline already, as well as forcing the user to make sure there is a Yes in the Norm Baseline column when a new ID is added for the first time.

    My code is...
    Code:
    'create a string to determine the closest baseline date to the measurement date for that field size
                
    basedateString = "[Equipment ID] = '" & equipID & "' AND [Norm Baseline] = True AND format([Survey Date],""ddmmyyyy"") < " _
                    & Format(sdate, "ddmmyyyy") & " AND [norm field size] <> null"
    
    'create a new string for DLookup criteria using that date
    basedate = DMax("[Survey Date]", "[results_hutt_dig]", basedateString)
    Using the Locals Window, when I choose 1/5/14, I can easily see that the basedateString is equal to
    Code:
    "[Equipment ID]" = 'ID.A' AND [Norm Baseline] = True AND format([Survey Date],"ddmmyyyy") < 01052014 AND [norm field size] <> null"
    which looks okay to me. Yet it returns null to basedate. However, an earlier value I entered works okay, and appears to be identical in structure.

    It is important to note that the Survey Date column might not be chronological and that different IDs will be littered through in any order.

    Any ideas?

    Thank you

  2. #2
    Markb384 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    44
    Just added another line to the table (2/5/14). It also debugs out, unless I convert 1/5/14 to a Yes in Norm Baseline, in which case it works perfectly. To me, this suggests that the equipment IDs need to be consecutive in the table, which is definitely far from ideal...

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

Similar Threads

  1. Outer join not returning null values.
    By Count Duckula in forum Queries
    Replies: 3
    Last Post: 08-15-2013, 10:03 AM
  2. Replies: 6
    Last Post: 07-24-2012, 03:02 PM
  3. Query Not Returning Null Fields
    By mgmirvine in forum Queries
    Replies: 2
    Last Post: 10-28-2011, 06:15 PM
  4. Query not returning null values
    By janelgirl in forum Access
    Replies: 5
    Last Post: 10-11-2011, 10:31 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