Results 1 to 3 of 3
  1. #1
    craig1988 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2014
    Posts
    82

    Incorrect syntax using Dlookup with a nested DMax

    SSer = Nz(DLookup("EndSerialNo", "qryG2OrderHistory", "AccNo=" & DMax("AccNo", "qryG2OrderHistory")), "N/A")

    Hi All



    I believe I have invalid syntax here.

    What I am trying to achieve is to look up the End Serial value in the query "qryG2OrderHistory" where the AccNo is equeal to the one appearing on a form. I want to return the newest EndSerialNo by using the DMax.

    Any suggestions??

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Is "AccNo" a "Text" or "Number" data type?

    If it is "Text" then you need quotes (single or double).
    SSer = Nz(DLookup("EndSerialNo", "qryG2OrderHistory", "AccNo='" & DMax("AccNo", "qryG2OrderHistory")) & "'", "N/A")

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    ...where the AccNo is equeal to the one appearing on a form.
    Your statement doesn't contain any reference to a form field, so it won't work as written, and the DMax should be where the DLookup is. Try something like this:

    SSer = Nz(DMax("EndSerialNo", "qryG2OrderHistory", "AccNo=" & [formcontrol]), "N/A")

    where [formcontrol] is the form control with the account number.

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

Similar Threads

  1. DMax syntax
    By ramimarachli in forum Reports
    Replies: 14
    Last Post: 10-02-2013, 03:54 PM
  2. DLookup and DMax on a split form filtered sheet
    By JustLearning in forum Forms
    Replies: 12
    Last Post: 12-11-2012, 03:55 PM
  3. Incorrect syntax near keyword “ORDER"
    By k9drh in forum Import/Export Data
    Replies: 1
    Last Post: 06-13-2011, 07:36 AM
  4. append query: dlookup or dmax problem
    By jeffr27 in forum Queries
    Replies: 1
    Last Post: 05-10-2011, 09:25 AM
  5. DMAX syntax
    By tuyo in forum Programming
    Replies: 1
    Last Post: 03-24-2011, 12:15 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