Results 1 to 4 of 4
  1. #1
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116

    Autopopulating Table Field from Another Table

    Here is what I am trying to accomplish. I have two tables. The first (Table 1) contains a list of tasks that need to be completed, including a field for the person the task is assigned to ("Assigned Employee"). The second table (Table 2) contains a list of 5 employees who can be assigned to each task (i.e., the names of indiviudals who will populate the "Assigned Employee" field in the first table).



    I would like the "Assigned Employee" field in Table 1 to automatically populate with an employee from Table 2 each time a new record is created. Ideally, whatever program I use would cycle through each employee before reusign any of them to ensure assignments are distributed equally.

    Is there any way to accomplish this in access?

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    perhaps have a query along the lines of

    Code:
    SELECT employeePK, count(employeeFK) as Ctr
    FROM table2 lEFT JOIN table1 ON table2.employeePK=table1.employeeFK
    GROUP BY employeePK
    ORDER BY count(employeeFK)
    Then a second query based on that one

    Code:
    SELECT TOP 1 employeePK FROM qry1
    Finally in your form something like

    employeeFK=dlookup("employeePK","Qry2")


    The first query is ordering with the least assigned at the top, the left join ensures all employees are available. When starting that is all of them so the first one is effectively chosen randomly in the second query. Once assigned, the next time you add a new task, that employee is at the bottom, so TOP 1 will choose a different employee. This continues until they have all been assigned once. At which point the cycle starts again - but wont necessarily select TOP 1 in the same order.

  3. #3
    jojowhite's Avatar
    jojowhite is online now Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    432
    you can also add code to the BeforeInsert Event of the Form.
    Open any form and add some entries. See the code of the BeforeInsert event.
    Attached Files Attached Files

  4. #4
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Thank you both! Marking as solved.

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

Similar Threads

  1. Replies: 3
    Last Post: 12-17-2013, 05:14 AM
  2. Replies: 4
    Last Post: 03-22-2013, 10:58 AM
  3. Help with autopopulating a form
    By chulo in forum Forms
    Replies: 7
    Last Post: 02-20-2012, 03:57 PM
  4. subform not autopopulating
    By slimjen in forum Forms
    Replies: 32
    Last Post: 09-21-2011, 01:55 PM
  5. Autopopulating Forms
    By daniel.e.john in forum Access
    Replies: 3
    Last Post: 09-09-2011, 07:19 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