Bob Heygood
bheygood at abestsystems.com
Thu Jan 4 12:50:55 CST 2007
Hello Gustav,
Yeah for DAO and clones and bookmarks. As a developer who still always uses
DAO and just now updated to OFF2003, this is a great solution.
Works great except for one field which is a memo field. Does not copy that
field, tho copies other memo fields.
I will try some other data and see what is happening.
Thanks,
Bob
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Thursday, January 04, 2007 1:57 AM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Copy Record on form
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
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com