Duplicate Button

M

Mommio2

OK, I thought I could do this myself, but apparently I can't! Could some
kind soul please tell me what to add to the code for the Duplicate Command
Button to make it "blank out" a field in the table before it duplicates the
record? I want the field to stay filled in on the original record, but be
blank on the copy. Thanks!
 
M

Mommio2

Now I have the "blanking out" working, but it still gets the message box
telling me that it is pasting the duplicate record into a new table because
it could not write it to the current table. Why do I get this? How can I
make it write to the table I am in? Thanks!
 
M

Mommio2

I just figured out the problem, but I don't know how to fix it! The record
that gets pasted in the new table has the fields in the tab order of the
form, not in the order they are in on the original table. What gives and
how would I fix it? Thanks a bunch!
 
M

Marshall Barton

Mommio2 said:
OK, I thought I could do this myself, but apparently I can't! Could some
kind soul please tell me what to add to the code for the Duplicate Command
Button to make it "blank out" a field in the table before it duplicates the
record? I want the field to stay filled in on the original record, but be
blank on the copy.

It sounds like you are using the copy record wizard's code.
Unfortunately, that code is too simple minded for anything
except trivial situations.

A way that give you control over the situation is to copy
the fields one by one, which allows you to skip any fields
you don't want to copy (e.g. primary key) and set specific
values for those that need new values (e.g. date created).

Here's the general outline:

With Me.RecordsetClome
.AddNew
!f1 = Me.f1
!f2 = Me.f2
!f4 = Me.f4
!f7 = Now
. . .
.Update
' make new record current
Me.Bookmark = .LastModified
End With
 
M

Mommio2

Thanks for your help! Just to be sure I understand this, as I am still very
much a beginner, would you please write out just one line for me? Let's say
that my table is called "Students" and the first field I want to copy is
"Date_Enr".

Also, if I want to "blank out" St_First_Name, would it be St_First_Name
= "" or would that make it blank in the first (copied from) record?

Really appreciate your help!
 
M

Marshall Barton

Just replace my example field names (f1, f2, etc) with your
**field** names. For example, to copy the Date_Enr field:
!Date_Enr = Me.Date_Enr

Make absolutely certain that you use the field names in the
form's record source table/query, not the names of controls
on the form (unless a control has the same name as its bound
field).

To leave a field blank when you do not want to copy it, just
leave out that line. The field will then be assigned its
default value (or, more commonly, Null if there is no
default value).

Since we are operating on the form's recordset, the table
itself is only referred to indirectly through the form's
record source. There is no need for this code to be aware
of the table name.
 
Top