Results 1 to 6 of 6
  1. #1
    gunitinug is offline Novice
    Windows 10 Access 2007
    Join Date
    Aug 2017
    Posts
    23

    Creating a record to another table automatically whenever a record is created

    My question concerns two tables, jobreport_tbl and stock_tbl:

    jobreport_tbl:
    groupID (Autonumber)
    jobdate
    client


    technician
    ...

    stock_tbl:
    stockID (Autonumber)
    stockGroup
    productRef
    qty



    Now, every time I enter a record in jobreport_tbl, I want to create a record in stock_tbl with stockGroup equaling groupID.

    I am trying to do this using table macros. I'm thinking the one I want is After Insert macro, createRecord and then setfield macro, but so far it doesn't work as I intended.

    THX

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    make a parent/child form.
    job report table as the parent,
    the subform connected to stock_tbl.
    join them on the like fields.

    then when you save JobReport, you can enter a StockTbl entry and they will both get the same ID.
    or
    you can make a macro to add a random item upon parent save.

  3. #3
    gunitinug is offline Novice
    Windows 10 Access 2007
    Join Date
    Aug 2017
    Posts
    23
    Quote Originally Posted by ranman256 View Post
    make a parent/child form.
    job report table as the parent,
    the subform connected to stock_tbl.
    join them on the like fields.

    then when you save JobReport, you can enter a StockTbl entry and they will both get the same ID.
    or
    you can make a macro to add a random item upon parent save.
    THX but I want stock_tbl to have multiple occurrence of stockGroup. ie. can have more than one entry with the same stockGroup.

  4. #4
    gunitinug is offline Novice
    Windows 10 Access 2007
    Join Date
    Aug 2017
    Posts
    23
    I tried:

    Code:
    jobreport_tbl : After Insert :
    Create a record in stock_tbl
       Set field
          Name stock_tbl.stockGroup
          Value = [jobreport_tbl].[groupID]

  5. #5
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    The answer ranman256 provided does allow for multiple occurrences of stockGroup per jobreport. If you switch your child form format options Allow Datasheet View->Yes and Default View->Datasheet it might make it more obvious.

    That said, I mocked up the tables from post #1 and your macro code from post #4 and it works for me. Maybe you have a required field in the stock_tbl that you've forgot to set as well?

  6. #6
    gunitinug is offline Novice
    Windows 10 Access 2007
    Join Date
    Aug 2017
    Posts
    23
    Quote Originally Posted by kd2017 View Post
    The answer ranman256 provided does allow for multiple occurrences of stockGroup per jobreport. If you switch your child form format options Allow Datasheet View->Yes and Default View->Datasheet it might make it more obvious.

    That said, I mocked up the tables from post #1 and your macro code from post #4 and it works for me. Maybe you have a required field in the stock_tbl that you've forgot to set as well?
    productRef field (foreign key) from stock_tbl is linked to product_tbl 's productID (primary key). Maybe that's why...

    yep... i setfield productref = 2 and it works.

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

Similar Threads

  1. Replies: 2
    Last Post: 03-16-2017, 05:50 AM
  2. Record Creating Automatically
    By baskey in forum Queries
    Replies: 5
    Last Post: 02-06-2014, 10:26 AM
  3. Creating a Record that automatically adds more records
    By fatimah25 in forum Database Design
    Replies: 5
    Last Post: 08-22-2012, 02:07 PM
  4. Replies: 1
    Last Post: 04-24-2012, 02:36 PM
  5. Replies: 7
    Last Post: 04-17-2012, 11:53 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