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!

Copy a single field from every record

Status
Not open for further replies.

supervi

MIS
Mar 22, 2003
61
CA
Just a quick question.

I have a subform with a boatload of records. Can someone give me the code to copy the text in a particular field from every single record. So that i can go into a blank version of that same subform and paste it. This would result in the new subform creating a whole bunch of records with the information from that one field populated for each record.

It would also be nice if I could store the results in a variable of some sort

**Note, every record in this subform has this field, so no conficts their

Thanks
 
Supervi,

Think in terms of 'recordsets'. I form has a recordset as its datassource. Actually the form can only 'look' at a finite number of the records in a recordset. Often only one. Suppose you wish to copy a field from a recordset which is tied to a table. named "One" to the same postion in a table named "TWO" The fields can be named in a number of ways - one is the position starting with zero and ending with the number of fields minus 1. Lets say you wish the third field in "One" to copy to the third field in "Two"

Using a cmd button's click event

private sub command_click0()

Dim r1 as dao.recordset, r2 as dao.recordset

set r1 = currentdb.openrecordset("One")
set r2 = currentdb.openrecordset("Two")
'test one for the certainty of records - omitted here
r1.movelast
r1.movefirst

do while not r1.eof

r2.addnew
r2.fields(2) = r1.fields(2)
r2.update
r1.movenext
loop

r1.close
r2.close
set r1 = nothing
set r2 = nothing
msgbox "The Deed is Did!"
exit sub


rollie @bwsys.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top