[AccessD] Copy Record on form

Gustav Brock Gustav at cactus.dk
Thu Jan 4 03:57:21 CST 2007


Hi Bob

As always, turn to DAO for a speedy method:

Private Sub btnCopy_Click()

  Dim rstSource   As DAO.Recordset
  Dim rstInsert   As DAO.Recordset
  Dim fld         As DAO.Field

  If Me.NewRecord = True Then Exit Sub
  
  Set rstInsert = Me.RecordsetClone
  Set rstSource = rstInsert.Clone
  With rstSource
    If .RecordCount > 0 Then
      ' Go to the current record.
      .Bookmark = Me.Bookmark
      With rstInsert
        .AddNew
          For Each fld In rstSource.Fields
            With fld
              If .Attributes And dbAutoIncrField Then
                ' Skip Autonumber or GUID field.
              Else
                ' Copy field content.
                rstInsert.Fields(.Name).Value = .Value
              End If
            End With
          Next
        .Update
        ' Go to the new record and sync form.
        .MoveLast
        Me.Bookmark = .Bookmark
        .Close
      End With
    End If
    .Close
  End With
  
  Set rstInsert = Nothing
  Set rstSource = Nothing
  
End Sub

Also, disable the button on a new record:

Private Sub Form_Current()

  On Error Resume Next
  Me!btnCopy.Enabled = Not Me.NewRecord
  
End Sub

/gustav


>>> bheygood at abestsystems.com 04-01-2007 05:47 >>>
Hello to the list,

When I select a record on a form and copy it and paste append, I seem to
only get a new record with data in those fields which have a visible control
on the form.

I have tested this and am wondering if someone could do the same.
My need is to only display some fields with controls on the form but when
coping the record, have all the fields data be pasted into the new record.
This seems to be the case whether I do it from the menu items manually or
use code using the 

   DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.RunCommand acCmdPasteAppend
Or 
	DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
Methods.

I am totally out of space on this form and would like this to work.
Otherwise I guess I will have to use SQL in the code.

A2003

TIA

Bob Heygood





More information about the AccessD mailing list