Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DUPLICATING A RECORD + SUBFORM LINES

Status
Not open for further replies.

fsweb2002

Programmer
Apr 11, 2002
94
TR
Hi there
I have a record header (client details, invoice number, etc) and a subform which displays a number of lines for than "invoice".

I need to do exact copies of them by simply clicking a button when displaying the current one.
For example, I am viewing (form) invoice no.555 with 3 subform lines.
I then like to click on a button which will duplicate the invoice (obviously with a new invoice number, which is an autonumber, and is the only field that doesn´t get duplicated), as well as all the subform lines.

I then want to give the focus (or show) the newly created copy on the form, discarding the 'old' invoice details.

Is there a fast way of doing this with code?

thanks in advance
 
The best way I can think of is rst.AddNew. To get the AutoNumber, probably just MoveLast and check the number, then add 1. You can copy the fields individually.

Dim rst As Recordset
Dim num As Long
Set rst = CurrentDb.OpenRecordset(&quot;<tablename>&quot;, dbOpenDynaset)
rst.MoveLast
num = rst!<autonumber> + 1
rst.AddNew
rst!<autonumber> = num
rst!<fieldname> = Me.<controlname>
...
rst.Update

Similar method for line items (except autonumber, of course).

To move the focus, you can use either rst.MoveLast or rst.FindFirst &quot;<autonumber = &quot; & num. Although MoveLast would work in this case, FindFirst would be more sure to be accurate. Then,
Me.Bookmark = rst.Bookmark
 
fsweb2002

I have the same problem as you and if you find out how to do it could you let me know?

I could do with the full code - as I'm not that good at it

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top