Tim Kiebert wrote a script that worked perfect on a single table but isn't working within the set I'm using. After five hours of rebuilding databases and extensive testing I now know the problem occurs when the table does not contain a sequential adm_nr. Within my set a adm_nr is only produced after data is entered. I did explain this in an earlier post (see quote).
In my attachment you'll see the �adm hoger beroep� table contains five records: BBB 0001, BBB 0002, BBB 0003, BBB 0004 and BBB 0008. On the form is a button with a script that copy's two fields from the �adm hoger beroep� table to the "factuur" table. When standing on record 8 the script will not copy the fields and will produce an error message: �record number is past end of table�. When the records BBB 0005, BBB 0006 and BBB 0007 are added to the �adm hoger beroep� table the script will work.
Can the script be adjusted so it will work in both cases (with and without a sequential adm_nr)?
The script I'm using is:
topparent.commit() 'Save record in current form.
rec_num = recno() 'get record number of current record
tbl1 = table.open("adm_hoger_beroep") 'open a new instance of the same table
tbl1.fetch_goto(rec_num) 'find the current record in the new instance of the table
vCurrInv = tbl1.hb_code 'use you actual invoicenumber field here
tbl2 = table.open("factuur")
tbl2.order("f_omschrf") 'Order the table because fetch_find in the next line needs to
'have the table ordered on the field in which it is looking
'Substite your actual invoicenumber field here for table two.
If tbl2.fetch_find(vCurrInv) > 0 then 'If current invoice is found in table 2 then the record
tbl2.change_begin() 'number is returned which is greater than 0 so table 2
tbl2.F_client = tbl1.hB_CLIENT 'is put in change mode.
tbl2.change_end()
Else 'If invoice number is not found then the record number
tbl2.enter_begin() 'with the nearest match is returned but as a negative value
tbl2.F_client = tbl1.hB_CLIENT
tbl2.f_omschrf = tbl1.hb_code 'so it will be less than 0 which cause the table to be put
'into enter mode.
' and so on until you have filled all of the fields
'in the destination with values from the current record
tbl2.enter_end(.T.)
end if
tbl1.close()
tbl2.close()
In my attachment you'll see the �adm hoger beroep� table contains five records: BBB 0001, BBB 0002, BBB 0003, BBB 0004 and BBB 0008. On the form is a button with a script that copy's two fields from the �adm hoger beroep� table to the "factuur" table. When standing on record 8 the script will not copy the fields and will produce an error message: �record number is past end of table�. When the records BBB 0005, BBB 0006 and BBB 0007 are added to the �adm hoger beroep� table the script will work.
Can the script be adjusted so it will work in both cases (with and without a sequential adm_nr)?
Originally posted by werder101010
View Post
The script I'm using is:
topparent.commit() 'Save record in current form.
rec_num = recno() 'get record number of current record
tbl1 = table.open("adm_hoger_beroep") 'open a new instance of the same table
tbl1.fetch_goto(rec_num) 'find the current record in the new instance of the table
vCurrInv = tbl1.hb_code 'use you actual invoicenumber field here
tbl2 = table.open("factuur")
tbl2.order("f_omschrf") 'Order the table because fetch_find in the next line needs to
'have the table ordered on the field in which it is looking
'Substite your actual invoicenumber field here for table two.
If tbl2.fetch_find(vCurrInv) > 0 then 'If current invoice is found in table 2 then the record
tbl2.change_begin() 'number is returned which is greater than 0 so table 2
tbl2.F_client = tbl1.hB_CLIENT 'is put in change mode.
tbl2.change_end()
Else 'If invoice number is not found then the record number
tbl2.enter_begin() 'with the nearest match is returned but as a negative value
tbl2.F_client = tbl1.hB_CLIENT
tbl2.f_omschrf = tbl1.hb_code 'so it will be less than 0 which cause the table to be put
'into enter mode.
' and so on until you have filled all of the fields
'in the destination with values from the current record
tbl2.enter_end(.T.)
end if
tbl1.close()
tbl2.close()
Comment