Results 1 to 5 of 5
  1. #1
    ashraf is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    37

    Question Adding Data to a linked table for multiple filtered records on the main table

    Hi,


    I've One to many linked tables by a short text field "ItemID", the main table "MainT" contains 100s of records, the linked table "DataT" is blank & contains 3 fields; "ID", "ItemID" and "Job", jobs are listed on a table "JobT"As shown on the below picture.

    Is it possible to filter "MainT" by one or many of its fields then insert many "job"s records into the linked table "DataT" for all filtered record on "MainT"?
    e.g. If I filtered the "MainT" by material "SS" the result will be 2 records (A9 & A10) then from an unbounded controller(s) I will select 3 jobs to be added to the "DataT" for all filtered items i.e. 3 jobs will be added to A9 & to A10 on "DataT".

    Note: Access example is attached

    Targeted items to be added to DataT
    ID ItemID Job
    10 A9 Cutting
    11 A9 Forming
    12 A9 Welding
    13 A10 Cutting
    15 A10 Forming
    16 A10 Welding

    Note: I used Multi Values Field for Job on the main table before but I changed to a linked table due to its difficulty for selecting, copying, editing and erasing.
    Click image for larger version. 

Name:	Capture.JPG 
Views:	19 
Size:	99.6 KB 
ID:	36917
    Attached Files Attached Files
    Last edited by ashraf; 01-14-2019 at 06:17 AM. Reason: Adding Access Example

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    You want to batch create records instead of record-by-record data input. This commonly involves an INSERT SELECT sql action.

    Can build a query object with static criteria.

    INSERT INTO DataT(ItemID, JobID) SELECT ItemID, JobID FROM MainT, JobT WHERE ItemID IN("A9","A10") AND JobID IN(1,2,4);

    Note lack of JOIN clause in the SELECT. This is a Cartesian association for the 2 tables because they don't have relationship. Unfortunately, this type of query can perform very slowly with large datasets.

    Allowing the IN() criteria to be dynamic will require VBA code that loops through multi-select listboxes to build the arrays of elements then constructing SQL statement in VBA and use CurrentDb.Execute to run it. This SQL would still be utilizing Cartesian query so if it is slow, VBA procedure will be more complicated to avoid Cartesian query approach.


    Glad you learned about multi-value field issues early on.
    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
    ashraf is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    37
    Thanks June7 for your quick responding.
    Few days ago I was trying with to make it dynamic with DoCmd.RunSQL but failed
    My be Multi selection list is a good Idea, I'll try to use it with CurrentDb.Execute



  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    This article demonstrates looping listbox to build array for IN() criteria. http://allenbrowne.com/ser-50.html
    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
    ashraf is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    37

    Thumbs up

    Thanks June7 finally it works, multi-Select Listbox was good idea instead of using subform

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

Similar Threads

  1. Replies: 4
    Last Post: 01-18-2017, 12:41 PM
  2. Replies: 6
    Last Post: 06-24-2016, 06:59 AM
  3. Adding data to an external linked table
    By Toasty in forum Import/Export Data
    Replies: 2
    Last Post: 06-12-2014, 07:10 AM
  4. Adding data from linked table to existing table???
    By claysea in forum Import/Export Data
    Replies: 3
    Last Post: 02-21-2013, 12:23 PM
  5. Replies: 3
    Last Post: 11-04-2012, 09:25 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