help with coding

S

Sheela

I have a table, table1 with fields fild1, field2,..start
position, End Position.
And also another table, table2 with fields field1, field2,
.. Position.
I need to insert data from table 1 to table 2, all the
fields has same information from the table1, except
position field.
The position field value starts from table1.start position
and ends with table1.end position.
It might be easy to understand if I give an example as
follows:
Could some one please help me how to do this?
TIA.
Sheela.

Table1:
Field1 field2 start position end position
A A 1 3
B B 8 9
....

Table2:
Field1 field2 Position
A A 1
A A 2
A A 3
B B 8
B B 9
....
 
A

Albert D. Kallal

Ok..note too hard....

dim rstT1 as dao.RecordSet
dim rstT2 as dao.RecordSet
dim strCurrentGroup as string
dim strGroup as string
dim intStart as integer
dim intEnd as interger

set rstT1 = currendb.OpenRecordSet("table1")
set rstT2 = currentdb.OpenRecordSet("table2")

do while rstT1.EOF = false

intStart = rstT1!Start
intEnd = rstT1!End
for i = intStart to intEnd
rstT2.AddNew
rstT2!Field1 = rstT1!Field1
rstT2!Field2 = rstT1!Field2
rstT2!Position = i
rstT2.Update
next i
rstT1.movenext
loop

rstT1.Close
set rstT1 = nothing

rstT2.Close
set rstT2 = nothing
 
S

Sheela

Thanks so much. I think i might need to add a tool or some
thing to make this code to work.
I am running this code on a command click, Access is
giving an error at the line:
Set rstT1 = currendb.OpenRecordset("table1")
The error is:

run time error 42, "Object Reqired".
Thanks for your help.
Sheela.
 
S

sheela

Sorry, the code works fine, i just had to define current
database. Thanks so much.
sheela
 
A

Albert D. Kallal

Sorry, the code works fine, i just had to define current
database. Thanks so much.
sheela

You welcome...I typed that code right into this email.......if you look
closely..you can see that I did not use the code editor..but it all was air
code.

And, the currendb...is actauly a type-o...I meant to type:

Set rstT1 = currentDB.OpenRecordSet("table1")

The above way eliminates the need to define the currentdb as you can use it
directly right in the expression...

Anyway..glad I could help....
 

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

Top