New record based on current record

  • Thread starter Thread starter Ed
  • Start date Start date
E

Ed

I am in a form and I want to create a new record based on all the
information in the current record.

Is there a quick and simple way or do I have to copy each control?

Ed
 
In form design view, there is a command button wizard that writes the code
to duplicate the record.

It is very basic and it fails if the form has anything non-standard (e.g.
calculated controls), but it may suit your needs if you want all fields
duplicated.
 
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim ctl As Control
Dim MyQuote As String

For Each ctl In Me

If ctl.Tag = "Data" Then

If Not IsNull(ctl) Then
ctl.DefaultValue = Chr(34) & ctl & Chr(34)
End If

End If
Next ctl

End Sub
--
Put this code in the Form Property and then in each field you want to be
duplicated into the new record place the word DATA in the TAG PROPERTY.

This will only make a record in a new instance of use. I.e. you input a new
record it will duplicate after that it will not duplicate from the last
record input unless it was input in that instance.

HOPE THIS HELPS



Hansford D. Cornett
 
Ed, the approach I prefer to use is to AddNew to the RecordsetClone of the
form, and then display the new duplicate. Sample code in this link:
http://allenbrowne.com/ser-57.html

You can ignore the block that says:
'Duplicate the related records
That part is for duplicating all the matching records in a subform as well.

Between the .AddNew and .Update, you list the fields you want duplicated.
Just don't list any calculated fields, or fields you don't want duplicated.
If the want the new record to have today's date, you can do that to (as in
the example.)
 
Back
Top