Results 1 to 6 of 6
  1. #1
    tsgtnissen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    28

    Question Access Button to Auto Populate default data to a table

    Hello!



    Im working on a very simple database that tracks tasks that are assigned to users. I have setup two tables called "Contacts" and "Tasks". In a perfect would I would like to auto populate 3 brand new tasks each time i create a new user // two tasks would be assigned to the "INDOC" tab and 1 task to the "blk 1" tab. I am using a query to filter the lists on each tab based on a field called "Block" Currently my user datebase looks like this:


    Click image for larger version. 

Name:	i1.PNG 
Views:	18 
Size:	53.8 KB 
ID:	42839

    the tabs look like this ...

    Click image for larger version. 

Name:	i3.PNG 
Views:	17 
Size:	37.4 KB 
ID:	42841

    the tasks table would need default info auto populated this is what my table looks like...

    Click image for larger version. 

Name:	i2.PNG 
Views:	17 
Size:	23.1 KB 
ID:	42840



    Thank you so much for the help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Execute INSERT action SQL statements to create records. But first have to commit new user record to table before records in related tables can be created. What are the foreign key fields?

    Advise not to use spaces nor punctuation/special characters in naming convention. PctComplete would be better than % Complete.
    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
    tsgtnissen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    28
    Where would i find my foreign key fields ?>

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    I should have said "foreign key field" - singular.

    It is the field in Tasks table that saves primary key (what is that field?) from Contacts table.
    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
    tsgtnissen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    28
    First, thank you so much for helping me with this issue. YOUR patience and kindness is greatly appreciated!

    I believe the key field is "ID"


    Click image for larger version. 

Name:	i4.PNG 
Views:	16 
Size:	25.4 KB 
ID:	42843

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    That is primary key in Contacts. Now what field in Tasks saves that ID as foreign key?
    Trying to understand how tables are related.

    I am guessing it is the AssignedTo field.

    Oh, and what are TaskList ID's of tasks you want to create?

    So as soon as new contact record is saved, need to grab that new ID and use it to create Task records.

    Real trick is figuring out what event to put code into. Perhaps button Click.

    If Me.Dirty Then Me.Dirty = False
    CurrentDb.Execute "INSERT INTO Tasks(AssignedTo, TaskID) VALUES(" & Me.ID & ", 1)"
    CurrentDb.Execute "INSERT INTO Tasks(AssignedTo, TaskID) VALUES(" & Me.ID & ", 2)"
    CurrentDb.Execute "INSERT INTO Tasks(AssignedTo, TaskID) VALUES(" & Me.ID & ", 3)"





    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: 3
    Last Post: 09-05-2016, 10:56 AM
  2. Replies: 3
    Last Post: 02-25-2015, 04:48 PM
  3. Replies: 5
    Last Post: 01-24-2015, 11:49 AM
  4. Replies: 2
    Last Post: 07-07-2014, 09:19 AM
  5. Replies: 1
    Last Post: 08-22-2012, 01:24 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