Results 1 to 7 of 7
  1. #1
    KBNETGUY is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    26

    Adding Records To a Table

    Hey folks I have a Customer Table CC_Customer with an associated form page. After adding a record on the form page I would like to Auto Insert Records into another table called CC_CustomerDisc

    CC_CustomerDisc table looks like this:

    Customer_Number - This is the unique ID for the newly added customer
    Disc_ID - This is the ID associated to a table called CC_DiscCat. This table contains discount that each customer is eligible to receive

    When a New Customer is added I would like CC_CustomerDisc table to be auto populated for example

    New Customer gets added. The Customer_Number = 100
    Then loop through the various CC_DiscCat records (in this case there are about 17 categories) and insert the Customer_Number along with each Disc_ID as a separate record. Alternatively I could use a button on the new page that says Add Customer Discounts. HOWEVER to prevent from hitting the button multiple times, there needs to be code that checks to see if the Customer_Number already exists. If it does then maybe dont even display the button. Not sure

    CC_CustomerDisc (table)
    Customer_Number | Disc_ID
    100 | 1
    100 | 2
    100 | 3
    100 | 4
    100 | 5
    100 | 6
    100 | 7
    100 | 8
    100 | 9
    100 | 10
    100 | 11
    100 | 12


    100 | 13
    100 | 14
    100 | 15
    100 | 16
    100 | 17

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can just execute an append query that gets categories from the table containing them and the customer from the form. You can test first with a DCount().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    KBNETGUY is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    26

    Question, How do I use the Form....

    Quote Originally Posted by pbaldy View Post
    You can just execute an append query that gets categories from the table containing them and the customer from the form. You can test first with a DCount().
    Ok BUT, how do we combined into one procedure:
    EXECUTE Append Query and looping through it to also add the Customer_Number .

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You don't loop through anything. The append query would refer to the form for the customer number. Like:

    INSERT INTO TargetTable(CustomerField, DiscountField)
    SELECT Forms!FormName.TextboxName, Disc_ID
    FROM Tablename
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    KBNETGUY is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    26
    Gotcha. That seams to work just fine. DO you know id there is a way to disable all the prompts. For example the first one is "Your About to run an append query..."

    The next one "Your are about to append 17 records..."

    Is there a way to now show these prompts ad then to refresh the current record to display the data in the sub-form for the parent record.

    Thanks again!~

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The first method:

    http://baldyweb.com/SQLWarnings.htm

    Execute won't work with the form reference.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, and you can requery the subform.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 08-20-2015, 09:49 PM
  2. Replies: 16
    Last Post: 02-06-2013, 09:23 AM
  3. Adding records to a table from a form
    By paulofranchico in forum Forms
    Replies: 1
    Last Post: 02-07-2012, 11:30 AM
  4. VBA code for adding records to a table
    By pwalter83 in forum Forms
    Replies: 3
    Last Post: 12-21-2011, 10:52 AM
  5. Adding records to existing table
    By Mclaren in forum Programming
    Replies: 5
    Last Post: 05-18-2011, 12:44 PM

Tags for this Thread

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