Results 1 to 9 of 9
  1. #1
    Yensid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    12

    How to display a specific field from the last record created.

    I am completely in over my head with Access, so please "spell" everything out. I do not understand even the simplest things yet. I will place my "names" in quotations for clarification, although I don't have the quotation marks in the actual names.

    I created a template called "AD - Assembly". In this table I have fields for:
    "AD_ RecNum" - This is the auto generated number field for each record, and also my Primary Key


    "Document Number" - This is the number that is being assigned to each document placed in this table. (i.e. AD-0001-001)
    "Description" - This is the description of each of the documents
    "Originator" - This is who is assigning the document a number
    "Origination Date" - This is a =CDate(Now()) field that will automatically generate the date and time the document was assigned a number.

    I then created a form called "AD - Assembly". On this form I created a field called "Last Record". I want to open the "AD - Assembly" Form, and have this "Last Record" field automatically filled with the "Document Number" filed of the last created record based on the "Origination Date" field.

    Please tell me how to do this.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Do you want to create a new record with a value from last created record?

    Or do you want to open form to the existing last created record?

    Regardless, code will be required and there is more than one way to achieve the result.
    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.

  3. #3
    Yensid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    12
    I want to create a new record.

    First - I have removed the "AD_ RecNum" field, and am going to rely on my "Document Number" as the Primary Key (as each document will have a unique number).

    Second - The person who is opening the form to create a new record needs to know what document number to assign. The numbering system used for these types of documents is AD-1001-001, AD-1002-001..AD-1010-001 and so on. I would auto-generate these number assignments, but I think I read somewhere that you can't do that if it has both numbers and letters.

    Third - So what I have is a field that will show the document number (AD-XXXX-XXX) of the last created record (based off the "Origination Date" =CDate(Now()) field???). For example, if the last record was AD-1001-001, it will display in that field, which will let the user know that the next number to create is AD-1002-001.

    Fourth - When a user opens the form to create the new record, I'd like to have this "Previous Record" field automatically filled in.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You want to generate custom unique ID. I use code that searches for the last ID and automatically increments the next ID. The process of generating ID is invisible to the user. I don't depend on user to not make mistake when typing a new number, number is generated for them.

    Common topic. Search forum or Google. Here is one https://www.accessforums.net/forms/a...ing-23329.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.

  5. #5
    Yensid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    12
    How? Below I've pasted the code from the page you suggested:

    Public Function NewSample() As String
    Dim strLabNum As String
    'search for aborted lab number and use that record, else if none then create new record
    strLabNum = Nz(DLookup("LabNum", "Submit", "IsNull(DateEnter)"), "")
    If strLabNum <> "" Then
    CurrentDb.Execute "UPDATE Submit SET DateEnter=#" & Date & "# WHERE LabNum='" & strLabNum & "'"
    Else
    strLabNum = Nz(DMax("LabNum", "Submit"), "")
    If strLabNum = "" Then
    'this accommodates very first generated number of blank database
    strLabNum = Year(Date) & "A-0001"
    Else
    'this accommodates change in year
    If Left(strLabNum, 4) = CStr(Year(Date)) Then
    strLabNum = Left(strLabNum, 6) & Format(Right(strLabNum, 4) + 1, "0000")
    Else
    strLabNum = Year(Date) & "A-0001"
    End If
    End If
    CurrentDb.Execute "INSERT INTO Submit(LabNum, DateEnter, EnterWho) VALUES('" & strLabNum & "', #" & Date & "#, '" & Form_Menu.tbxUser & "')"
    End If
    Form_SampleManagement.ctrSampleList.Requery
    NewSample = strLabNum
    End Function


    But I don't know how to modify things to work properly.

    If you could help, that would be great.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Posting unmodified code from suggested link is not helpful. I don't know your database and business processes to do coding for you. You will have to adapt code
    as you see fit and test it. This means you need to learn programming concepts, VBA language, and how to debug. Link at bottom of my post has guidance on debugging techniques.

    Google: Access introduction to programming
    http://office.microsoft.com/en-us/ac...010341717.aspx
    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.

  7. #7
    Yensid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    12
    I appreciate the help you HAVE given me, and the links you've suggested will be useful. I will continue to attempt figuring this out. Should there be anyone else out there with ideas on how I can accomplish my original question...I look forward to your suggestions as well.

    Copy/Paste from my original question above: On this form I created a field called "Last Record". I want to open the "AD - Assembly" Form, and have this "Last Record" field automatically filled with the "Document Number" filed of the last created record based on the "Origination Date" field.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You could try DMax expression in a textbox ControlSource:

    DMax("[Document Number]", "[table name]")
    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.

  9. #9
    Yensid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    12
    That worked perfectly (of course) - thank you!

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

Similar Threads

  1. Replies: 2
    Last Post: 08-02-2012, 01:47 PM
  2. Replies: 1
    Last Post: 08-01-2012, 12:50 AM
  3. Display record in unbound text field on form
    By MAABDOLAT in forum Forms
    Replies: 1
    Last Post: 07-25-2012, 06:10 PM
  4. Code to display latest record number field created?
    By rowardHoark in forum Programming
    Replies: 1
    Last Post: 01-31-2011, 08:03 AM
  5. Replies: 1
    Last Post: 04-11-2010, 04:05 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