By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 2,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

Recordset CopyRecord

P: n/a
Found some stuff on Google about this, but it was older and only applied
to form code when a table was being displayed.

Anyway, I am adding records to a recordset where the values I am
inserting are based on the values in the current record. The easiest
way to do this is to copy the current record, do an insert, and perform
the adjustments on the newly inserted record.

I am wondering if there is a more elegant way to do this than:

strFld1 = rst!Fld1
strFld2 = rst!Fld2
... etc ...

rst.AddNew
rst!Fld1 = strFld1
rst!Fld2 = strFld2
... etc ...

// Perform adjustments

.... because there are a lot of fields in the record.
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You could loop through the fields and refer to them by number:
For i = 0 to rst.Fields.Count - 1
Debug.Print rst.Fields(0)
Next

Depending on the context, you could copy from one recordset directly to
another (or to a new record in the clone set), copy them to an array, or use
the loop to build up the SQL string for an Append query statement.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"John Baker" <ba*****@ix.netcom.com> wrote in message
news:V4*******************@fe2.columbus.rr.com...
Found some stuff on Google about this, but it was older and only applied
to form code when a table was being displayed.

Anyway, I am adding records to a recordset where the values I am inserting
are based on the values in the current record. The easiest way to do this
is to copy the current record, do an insert, and perform the adjustments
on the newly inserted record.

I am wondering if there is a more elegant way to do this than:

strFld1 = rst!Fld1
strFld2 = rst!Fld2
... etc ...

rst.AddNew
rst!Fld1 = strFld1
rst!Fld2 = strFld2
... etc ...

// Perform adjustments

... because there are a lot of fields in the record.

Nov 13 '05 #2

P: n/a
Allen Browne wrote:
You could loop through the fields and refer to them by number:
For i = 0 to rst.Fields.Count - 1
Debug.Print rst.Fields(0)
Next


Aye, still have to store them somewhere so they can be refererred to
after that .AddNew. An array would do the trick I guess.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.