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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

repeating one record X number of times

Status
Not open for further replies.

rene316

Programmer
Jan 14, 2002
81
US
Hello,

Is there a way to repeat a record X number of times(X being however many you want) within a database. I have a database of 26 records. Each record has to be duplicated a certain amount of times(indicated by a number in a seperate field), is there a command I can use or mabye someone knows of some code that would help me do this. I usually do it in Excel, just cut and paste, but that is too time consuming, I need to speed up this process. Any help would be much appreciated.

Thank You,
Rene
 
VarRecNum=3 &&record you want to duplicate
VarTimesDup=20 &&number of times you want to add it
VarTable="c:\path\MyTable" &&file you want to do this to

use &VarTable
copy to TempDup for recno()=VarRecNum

for Counter= 1 to VarTimesDup
append from TempDup
endfor

 
do you really need to add records to the table is duplicates? or are you duplicating it for a form or report? Attitude is Everything
 
thanks baltman, i will try it. And danceman, yes I am duplicating the records for a client who wants to mail a letter to every person in a paticular mobile home park. One address but several trailer spaces (ie...space 1, space 2, space 3), rather than create a record and copy it out and then append it 254 times or whatever, I know how many spaces there are because there is a field that indicates it, I would rather just have a program go record by record, look at that field and repoduce the record that many times, and place a sequence number in another field starting at 1 ending when the record has been dupicated the specified number of times, and then start the sequence number over again at 1 for the next record, repeating for the specified number of times, and so on. so that is what i am trying to accomplish, but don't know how.
 
If I understand you correctly. I assume the following:

the report letter is the same, change the sequence number on the report.

loop through the table.

for each record do a for next loop base on the number of copies you need.
FOR i = 1 to your quanity
in your report use the 'i' as the sequence number on
the report.
REPORT FORM yourreport ......
NEXT

this way you do not need to add records to your table. If you still need a table, then I recommend to use cursors to hold the records. this way you do not need to modify the orginal table. Create the report on the new cursor. Attitude is Everything
 
I can think of another scenario. If the user wants the same addresses like rene316 stated, but also wanted to put the names in the respective records it would be beneficial to duplicate the records.

STORE 255 TO howmany
USE MyTable
SCATTER MEMVAR MEMO
FOR xxx = 1 TO howmany
INSERT INTO MyTable FROM MEMVAR
NEXT

Dave S.
 
Building on DSummZZZ's suggestion keeping the original table as is.

use mytable alias my
copy structure to newTable

sele my

scan
mhowmany=my.countfield &&use your count field from mytable
SCATTER MEMVAR MEMO
FOR nCnt = 1 TO mhowmany
INSERT INTO newTable FROM MEMVAR
NEXT
endscan
 
this is what i use:


set default to g:\mike\ala2081
if !used("RenesFile")
select 0
use RenesFile alias Mlty
else
select Mlty
use in Mlty
select 0
use RenesFile alias Mlty
endif
*
if !used("ExactCopyofRenesFile")
select 0
use ExactCopyofRenesFile alias Mlty2
else
select Mlty2
use in Mlty2
select 0
use ExactCopyofRenesFile alias Mlty2
endif
*
SET TALK OFF
* set console off
*!* debug
*!* suspend
Zero = 0
nCurrentRec = 0
*
select mlty
go top
SCAN while !eof()
nDisp = mlty.qty && number of trailor parks in field called qty
a = 1
nCurrentRec = nCurrentRec + 1
IF MOD(nCurrentRec,500) = 0 &&was 1000
iPercDone = round( ( nCurrentRec/RECCOUNT("mlty") ) * 100 ,0 )
wait "making poo-poo "+transform(nCurrentRec,"99,999,999")+" "+ ;
transform(iPercDone, "999")+"%" window nowait
endif (mod(nCurrentRec))
*
scatter memvar
*
do while .NOT. A=nDisp+1
a = a+1
Select Mlty2
append blank
gather memvar
ENDDO
Select mlty
* loop
Endscan
*set console on
SET TALK ON
use


Hope that helps Rene.

-Mike


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top