Results 1 to 12 of 12
  1. #1
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160

    Auto populate record based on last record

    HI Guys,

    I am working on a production database. Where Just storing the product and quantity being produced of a particular product on basis of each machine. Form has following fields:
    Date, Product, DayQty & NightQty.

    I was wondering if it is possible to auto populate product field of each new record automatically to what was entered in the immediate last record. Though the user has freedom to choose the product type and change it. Product field in form is Combo Box, where it is getting values from tblProduct & in tblProduction productID is being stored.

    Looking forward to your help.


    Thanks and Regards
    Deepak Gupta

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Try this:
    Code:
    Private Sub Form_Current()
        If IsNull(TempVars!tvProduct) Then Exit Sub
        If Not Me.NewRecord Then
            TempVars!tvProduct = Me.cboProduct.Value
        Else
            Me.cboProduct = TempVars!tvProduct
        End If
    End Sub

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    You might try using a variable or tempVar. It would be helpful if you showed us your form and/or a sample of the filled form.

  4. #4
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Dear Davegri & Orange,

    Thanks for your reply.

    Davegri, I am trying to understand your code, but sorry to say unable to understand in detail. As I am a total novice in VBA & access also I am a newbie. What I have been able to make out of your code till now, it would work if we were making entries repeatedly in a single instance, Where as I need the auto populate to work for the first time form is opened.

    I agree this might work for my problem, but slight modification might be required. Hence I am attaching my Access file for your reference. I need to Auto populate Product_FK automatically same as last record, If user needs he can change the value if required. I am opening the form through a macro in New Record mode (M1NewRecord).

    Thanks for all your help.
    Regards
    Deepak Gupta

    Prd.zip

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Prd-davegri-v001.zip
    Added form_open code to frmProductionM1.
    Form will now open with new record, initialized to the last product added to tblProductionM1.
    I hope that's what you described.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Cross posted with responses and sample database at http://www.utteraccess.com/forum/ind...ic=2048506&hl=

    Deepak --when you post the same question on multiple forums (CROSS POSTING)

    Please do the following:
    -tell readers that you have done so
    -identify a link to the other post(s)

    Here is why: https://www.excelguru.ca/content.php?184

  7. #7
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Dear Orange,

    Kindly look into the question asked on other forum. I have used the same DB but the question is totally different. Here I have asked how to auto populate a feild based on last record AND in the other link (Utter Access) I am just trying to find out is it possible to use 1 Form to feed data directly into 2 or 3 different tables.

    Still, if you feel that the questions are same, please accept my sincere apology and I will try to point out, in future if any related posts have been posted in different sites.

    Laslty, I am not a random poster who just keeps posting and feel forums are one of the best gifts of Internet, which help us in learning and solving our problems. Thanks to every one who is helping others, to get through there projects.

    Thanks and Regards
    Deepak Gupta

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Deepak,
    Not a problem. I just wanted you to know that cross posting is acceptable and encouraged. But the forums are "staffed" with volunteers who participate and share their knowledge freely. It is considered proper etiquette/netiquette generally to advise those who may be assisting and/or researching to post related links. I was not suggesting that you were a random poster.

    The table structure suggested on the other forum seems appropriate, but you know your environment better than readers.

    Good luck with your project.

  9. #9
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Thanks Orange, I totally understand and agree with your point of view.

  10. #10
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Thanks Davegri, solution works perfectly.

    Regards
    Deepak Gupta

  11. #11
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Glad to help. You'll have to add the code to the other 2 forms, adapting for the other 2 tables.

  12. #12
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Davegri, Already did that.

    Thanks

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

Similar Threads

  1. Auto Populate new record in Junction Table.
    By Deepak.Doddagoudar in forum Forms
    Replies: 6
    Last Post: 03-31-2018, 12:32 PM
  2. Replies: 2
    Last Post: 08-05-2014, 04:07 PM
  3. Combo Box Auto Populate-Applies to EVERY Record
    By AccessNewb11 in forum Access
    Replies: 3
    Last Post: 05-22-2014, 11:45 AM
  4. Replies: 8
    Last Post: 07-06-2013, 05:13 PM
  5. Replies: 3
    Last Post: 07-26-2012, 03:55 PM

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