duplicate records (1 Viewer)

kitty77

Registered User.
Local time
Today, 10:41
Joined
May 27, 2019
Messages
693
I have a form. The form has several fields. I would like to enter (with a barcode reader) a value in field "Field2", then duplicate that record after that value is entered by the barcode reader. I have it working but it creates some extra blank records? How can I do this or what am I doing wrong? It is set on lost focus.

Thanks...


Private Sub Command10_Click()
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend
[Field2] = ""
Me.[Field2].SetFocus
End Sub
 

Ranman256

Well-known member
Local time
Today, 10:41
Joined
Apr 9, 2015
Messages
4,339
scan the barcode,
save,
run append query to do the copy.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:41
Joined
May 7, 2009
Messages
19,175
maybe change to code a bit:
Code:
Private Sub Command10_Click()
    Dim fld As DAO.Field
    Dim coll As Object
    Dim i As Integer
    Dim vkeys As Variant
    
    Me.Dirty = False
    Set coll = CreateObject("Scripting.Dictionary")
    With Me.Recordset
        .Bookmark = Me.Bookmark
        For Each fld In .Fields
            If fld.Attributes And dbAutoIncrField Then
                'do nothing on autonumber field
            Else
                coll.Add key:=fld.Name, Item:=fld.value
            End If
        Next
        vkeys = coll.keys
        .AddNew
        For i = 1 To coll.count
            .Fields(vkeys(i - 1)) = coll(vkeys(i - 1))
        Next
        .Update
        Me.Bookmark = .Bookmark
    End With
    Me.Field2 = ""
    Me.SetFocus
End Sub
 

Users who are viewing this thread

Top Bottom