duplicate record command button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomvula
    New Member
    • Jul 2008
    • 6

    duplicate record command button

    hi guys
    i need help, i have a form which is diplayed in a Datasheet view with more that 2 hundred records, when a user needs to add new entries i want him/her to select atleast 5 or more rows and click duplicate record button to duplicate those five records but at the moment only 1 record is getting duplicated
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Hi nomvula,

    Best to check the code of this sample:
    Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!

    It shows how to select the rows from a datasheet subform and will allow you to write the needed INSERT loop.

    Nic;o)

    Comment

    • nomvula
      New Member
      • Jul 2008
      • 6

      #3
      thanks Nico, i'll have a look at that

      Comment

      • nico5038
        Recognized Expert Specialist
        • Nov 2006
        • 3080

        #4
        In the subform the code:
        Code:
        Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Parent.txtSelLength = Me.SelHeight
        Parent.txtSelstart = Me.SelTop
        
        Dim rs As Recordset
        Dim intI As Integer
        
        Set rs = Me.RecordsetClone
        
        rs.MoveFirst
        intI = 1
        While intI < Me.SelTop
         intI = intI + 1
         rs.MoveNext
        Wend
        'now positioned on the first
        
        'Init resultfield
        Parent.txtSelected = ""
        
        intI = 0
        
        While intI < Me.SelHeight
         Parent.txtSelected = Parent.txtSelected & " " & rs!Field1
         intI = intI + 1
         rs.MoveNext
        Wend
        
        Set rs = Nothing
        
        End Sub
        Is filling the fields of the mainform with the rows and more important the keys (here field1). The same loop can be used to execute an insert statement for duplicating the selected rows.

        What more do you need o know ?

        Nic;o)

        Comment

        Working...