Results 1 to 8 of 8
  1. #1
    SmartestIdiot is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    27

    Expression for Default Value

    I have a form that opens as a new record, but there is one field I would like to show the last value in the field "ControlNumber". I'm avoiding the VBA because of the security on the local machines. I have an expression in the default value property that looks like this:



    =Last([tblLeave]![ControlNumber])

    I just need the last control number to show in the form so the user can enter in the next sequential Control Number.

    I'm using Access 2003.

  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,641
    Don't think that will work, but try DMax() (or DLast(), but that often produces unexpected results).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Why are you leaving the entry of this control number to the user? You can populate it without the user having to touch it using the dmax function as pbaldy described. And what does VBA have to do with security you can set up trusted locations on your server or trusted files. At any rate if this is an important field and you want to 'force' a specific value you also want to be careful if you are using a BOUND form because if you actually populate the field then, say, open and close the form 10 times, you're going to end up with 10 blank records with just the controlnumber populated in your table.

  4. #4
    SmartestIdiot is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    27
    The Field I want populate is actually the key, so it won't produce multiple records with the same entry. The key is a combination of letters and numbers so its not something that can be predicted by access. I thought it would be easy to get the last value in a field, but it s turning out to be a headache.

  5. #5
    SmartestIdiot is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    27
    Still no luck. I'm avoiding VBA because every time I try to put a module in the form I get an alert message about empty cells or having the Have module property set to yes. Its a real pain.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    it sounds to me like you don't need this to be your primary key, if you make an autonumber your primary key that would be better. If this is something like a patient control number, or customer number that is an internal designation of your system and you can build that customer or patient number based on other fields in your data you can also carry this internal number through and calculate it at the time of data entry if it's a 'new' record. I would strongly recommend that you don't try to create your own PK if you're not extremely comfortable with VBA.

  7. #7
    SmartestIdiot is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    27
    I took the suggestion of using the autonumber as the primary key, however I am still have issues getting the text field to populate with the last control number using Dmax function in as the default value. I'm not sure if I'm approaching this the right way. I just know this is what I need. A txt box that will show the last control number entered so the user can add the next sequential control number.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Generation of custom unique identifier is a common topic.

    Here is one thread https://www.accessforums.net/access/...nce-40410.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-25-2013, 09:35 AM
  2. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  3. Replies: 4
    Last Post: 10-26-2012, 12:49 AM
  4. Default Value
    By Njliven in forum Access
    Replies: 1
    Last Post: 10-10-2012, 12:48 PM
  5. Set default value
    By accessnewb in forum Programming
    Replies: 3
    Last Post: 08-17-2011, 06:24 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