Allen Browne's CarryOver

G

Guest

Is there a way to duplicate the information for the current record instead of
always the last record?

Set rst = frm.RecordsetClone
If rst.RecordCount > 0 Then
rst.MoveLast
For i = 0 To frm.count - 1
Set ctl = frm(i)
If TypeOf ctl Is TextBox Then
If Not IsNull(rst(ctl.Name)) Then
ctl = rst(ctl.Name)
End If
ElseIf TypeOf ctl Is ComboBox Then
If Not IsNull(rst(ctl.Name)) Then
ctl = rst(ctl.Name)
End If
End If
Next
End If
 
C

Chris Reveille

Here is something I picked up from Sandra Daigle for
cloning the current record.

Here you go - this code will 'clone' the current record -
attach it to
whichever event makes sense for you. I don't know whether
this will work
with images but you can give it a whirl and let me know.

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -
'chg CustomerID to the name of your primary key field
If fld.Name <> "Customerid" Then
rst.Fields(fld.Name).Value = fld.Value
End If
Next fld
' If your Primary key (Customerid) is autonum you don't
need this
' otherwise, replace this with whatever method you use
for getting
' the next primary key value. This one is a simple
incrementing value
'
lngCustid = Nz(DMax("Customerid", "Customers"), 0) + 1
rst.Fields("Customerid") = lngCustid
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing

Good luck

Chris
 
G

Guest

Thank you for your help. I am not using images, so I don't know if it works
for them.

I had to save the record first before running this code, but other than that
it works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top