Results 1 to 7 of 7
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195

    Duplicating a selected amount of records

    Good Day all, @Orange, The Sun is up in Wales so WGM will beat you to this one



    I am trying add a selected amount of records based on 1 order number

    So if a Customer has got 20 x orders on 1 x Order No i am wanting to for example add 3 more so we end up with 23

    when i try the code below, I have added 3 when prompted by iInput then 35 records are added and not 23!!!

    Code:
    Dim x As Integer, iInput As Integer
    Dim strSQL As String, strOrderNo as String
    
    
    If Me.cboStatus = "Duplicate" Then
    
    
    iInput = InputBox("Enter How Many Records To Duplicate ?")
    
    
        For x = 1 To iInput
    
    
                strSQL = "INSERT INTO tblEdit " _
                    & "SELECT tblEdit.* " _
                    & "From tblEdit " _
                    & "WHERE (((tblEdit.OrderNo)= '" & strOrderNo & "'));"
        
                DoCmd.SetWarnings False
                    DoCmd.RunSQL strSQL
                DoCmd.SetWarnings True
        
                Me.Status = "Planning"
                
        Next
                If Me.Dirty Then Me.Dirty = False
                
                   Me.cboDelTo.SetFocus
                   Me.cboDelTo.SelStart = 0
                Forms!frmMainMenu!frmIndex1DS.Requery
        
        Debug.Print strSQL
    
    
    End If

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,994
    Break it down into steps.
    See how many records you get with the Select.

    FWIW if the orderno has 20 lines, then you will add 3 * 20? which I do not think is what you want.
    Normally a Cartesian query would solve this.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,737
    Dave,

    Please give us an example of an Order and OrderDetails.
    Paul is guessing as to what you want/need.
    So an example will help with context.

    I'm not sure what you mean by "duplicating".

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Guy's just passed my semi functioning brain, an input of 3 on a current order of 6 will be 18 + 3 (21 Records)

    I ned to a the primary key record number field to narrow the calculation down to 1 Record No x input of duplicates

    SO i have x 2 criterias, 1 OrderNumber and 1 x Record No from primary key field ?

    Will need to come back later on it...

    Kindest

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,994
    Nope
    First Pass 6 + 6 = 12
    Second Pass 12 + 12 = 24
    Third Pass 24 + 24 = 48
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,737
    Dave,
    " an input of 3 on a current order of 6 will be 18 "?????

    Consider: (Please revise to match your requirement)

    You have an Order(orderno 200) and that order currently involves 6 parts.
    You want to add 3 more parts to Orderno 200, so you end up with 9 parts on Orderno 200.

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Guy's i think i just have the calculation wrong like you have stated

    Like WGM has mentioned each selected value amount will just keep multiplying...

    I think i need to add:

    Multiply input selected by Dlookup RecordNo WHERE OrderNo = String

    I think that's solution, will try a little later but as always, thank you guy's for your input....

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

Similar Threads

  1. Append Query keeps duplicating records
    By AlexTheGr8 in forum Queries
    Replies: 3
    Last Post: 07-19-2019, 08:06 AM
  2. Multiple duplicating records
    By Pavel in forum Access
    Replies: 4
    Last Post: 05-23-2018, 05:21 AM
  3. Replies: 5
    Last Post: 06-24-2015, 02:45 PM
  4. Duplicating record, selected fields only
    By wanderanwills in forum Access
    Replies: 1
    Last Post: 03-28-2015, 08:04 PM
  5. duplicating records
    By kstyles in forum Queries
    Replies: 7
    Last Post: 12-31-2010, 02:31 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