Results 1 to 6 of 6
  1. #1
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160

    How to copy selected records from a continuous form

    Hi,
    I have a main form with a subform continuous form, each form on the continuous form contains FieldA, FieldB, FieldC and a YesNo Checkbox, there are also Fields D-E that are not on the form but in the table.
    On the main form is a button called "CopySelected Records". I want to select (click checkbox of) some of the continuous form records, and then click CopySelectedRecords to copy the selected records - Fields A-E - to a second table. What would be the code in the CopySelectedRecords_OnClick procedure?

    Thanks for any help


    David

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    it runs a query. docmd.openquery "qaCopyQry"
    the query would pull the data in the subform using the current record key . (does your subtable have key?, like an autonum to identify it?)
    it would be like

    qaCopyQry=select * from subtable where [id]=forms!fMasterForm!subform!form!txtID

    the query would see what record you are on. If you do not use autonums in the subform, you must supply lots of other fields:
    where [state]=forms!fMasterForm!subform!form!txtState and [name]=forms!fMasterForm!subform!form!txtName

    (not the greatest method but is works)

    When building the where clause, always use the BUILDER to get the pathname correct...
    forms!fMasterForm!subform!form!txtID

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    if the yesno control is bound to a field in your table, you need to query that table to identify which records have been selected. If it is not bound then selecting one will select all and you need a different approach. There is an example of how to make a continuous subform 'multi select' here https://www.access-programmers.co.uk...d.php?t=289116

  4. #4
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Ranman, Thanks for your reply, afraid I don't understand.
    I thought the query would be:
    Select * from subtable where [LinkChildField] = [LinkMasterField] and YesNoCheckbox = True

    When you say "autonums in the subform" do you mean the tables PK? - the table does have a PK - or are you referring to a key on the form?

    In your reply you only mention the query - I wanted to also copy the selected records to another table I don't see that part?

    Also you say "use the BUILDER to get the pathname correct", this is something I've spent many hours battling with, how do I use the Builder for this? is there a tutorial?

    Excuse my ignorance, I have alot to learn - and it's getting late!

    Thanks
    David

  5. #5
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Thanks for the link Ajax, looks like something I'll use. At the same time I'd like to copy all the selected records to another table is there a block copy or do I need to loop thru the results copying each record separately?

    Thanks
    David

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    I haven't check the actual code but you would use a single sql query to insert the data into another table. The filter string generated by the code would be used as a criteria. Perhaps something like

    SQLStr="INSERT INTO newTable (fld1, fld2, fld3...) SELECT fld1, fld2, fld3... FROM origTable WHERE PK IN (" & me.Selected & ")"
    currentdb.execute SQLStr

    replace table and field names with your own. the bit in red is the equivalent of the filter string created by the current code

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

Similar Threads

  1. Replies: 1
    Last Post: 03-07-2017, 06:32 AM
  2. Continuous Form - Delete Selected Records
    By soco3594 in forum Forms
    Replies: 9
    Last Post: 01-20-2016, 02:31 PM
  3. Replies: 3
    Last Post: 12-28-2015, 04:11 PM
  4. Replies: 8
    Last Post: 11-28-2015, 12:00 PM
  5. Continuous search form won't open selected record in view form.
    By IncidentalProgrammer in forum Programming
    Replies: 20
    Last Post: 03-24-2015, 02:53 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