Results 1 to 5 of 5
  1. #1
    hoodoo's Avatar
    hoodoo is offline Novice
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    15

    Smile Expression builder help? Another #name? problem

    Hello.

    Long story short, I am trying to set default value property to a field in a form to be the last/max CustomerID (which is autonumber) from a different table than the one the form is associated with.

    So far I've tried many expressions, but they always end up showing #name? error. Currently I'm using "=DLast([tblCustomer]![CustomerID];[tblCustomer])"

    I read that that error may appear due to taken alias or something, so I tried changing CustomerID to something else, but the error persists.

    I have GoToRecord New macro set to the form when it opens. What is interesting, if I open the form and press "Refresh All" in the ribbon, it somehow shows what I need (the most recently added ID from table tblCustomers in the form's field "Customer ID").

    Thanks already!
    Last edited by hoodoo; 11-27-2015 at 01:59 PM. Reason: correction

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Not sure that works (never tried), but all arguments are strings, so try

    =DLast("[CustomerID]";"[tblCustomer]")

    I'd personally use DMax, though it may not matter.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    What is the second tblCustomer for? "=DLast([tblCustomer]![CustomerID];[tblCustomer])"
    If it's a control name, it probably can't be resolved because it's ambiguous plus you have the reference in the criteria part of the expression, but you don't want criteria. I don't get your syntax either. Should it not be "=DLast("tblCustomer", "CustomerID")?
    As for any difference, I suppose none also, as long as we're talking autonumbers since even sort orders don't seem to affect which is last versus max.
    Just a thought since you are using auto number to construct a record id: would there be a problem if two users were doing this at the same time and one of them cancelled? Probably would not affect your DLast result, but it would create gaps. Probably not an issue - just wondering if it was considered.

  4. #4
    hoodoo's Avatar
    hoodoo is offline Novice
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    15
    Quote Originally Posted by pbaldy View Post
    Not sure that works (never tried), but all arguments are strings, so try

    =DLast("[CustomerID]";"[tblCustomer]")

    I'd personally use DMax, though it may not matter.

    Oh my god, man, I really don't understand wtf, but it worked! Thank You so much!!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Expression Builder Syntax Problem
    By maxmaggot in forum Queries
    Replies: 7
    Last Post: 06-14-2013, 08:29 AM
  2. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  3. Expression Builder Problem
    By benthamq in forum Forms
    Replies: 3
    Last Post: 10-07-2011, 01:02 PM
  4. Expression builder
    By PJ_d_DJ in forum Access
    Replies: 2
    Last Post: 02-24-2011, 03:38 AM
  5. Expression Builder
    By mistaken_myst in forum Access
    Replies: 2
    Last Post: 05-07-2008, 01:30 PM

Tags for this Thread

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