call records in subforms

J

jb

In Acess 2003, I need to select the first record from a subform to copy the
data in it to another subform with a VBA module (called from a macro outside
both forms and subforms), and then select the next record and do the same,
until the last record. The form/subForm that receives the data is blank and
its a new record.
I think that the Do and Do While procedure is the correct but I can't seem
to write the code to select the second record, the third and so on and copy
each row data to the other subform. I think also I need a counter to assist
in how many times to do the procedure. Can you help me? Thanks!
 
G

George Nicholson

No need to count.

Set rs =
Forms("parentformname").NameOfControlContainingFirstSubform.Form.Recordset
Do Until rs.EOF
'.....copy data from rs to 2nd subform
rs.MoveNext
Loop
 
J

jb

I am using this code and it is not copying the data from first record nor
advancing to second and third records:
DoCmd.Echo True, ""
Set rs = Forms("Form1").[Subform1].Form.Recordset


Do Until rs.EOF
Forms![ Form]![subform].Form![Field1] = Forms![ Form1]![
subform1].Form![ Field10]
Forms![ Form]![subform].Form![ Field2] = Forms![ Form1]![
subform1].Form![Field20]
Forms![ Form]![subform].Form![Field3] = Forms![ Form1]![
subform1].Form![Field30]
rs.MoveNext


Loop

Thank you
 
G

George Nicholson

Dont copy from the form. Copy from the recordset.

Set rs = Forms("Form1").[Subform1].Form.Recordset

Do Until rs.EOF
Forms![ Form]![subform].Form![Field1] = rs![Field10]
Forms![ Form]![subform].Form![ Field2] = rs![Field20]
Forms![ Form]![subform].Form![Field3] = rs![Field30]
rs.MoveNext
Loop

--
HTH,
George


jb said:
I am using this code and it is not copying the data from first record nor
advancing to second and third records:
DoCmd.Echo True, ""
Set rs = Forms("Form1").[Subform1].Form.Recordset


Do Until rs.EOF
Forms![ Form]![subform].Form![Field1] = Forms![ Form1]![
subform1].Form![ Field10]
Forms![ Form]![subform].Form![ Field2] = Forms![ Form1]![
subform1].Form![Field20]
Forms![ Form]![subform].Form![Field3] = Forms![ Form1]![
subform1].Form![Field30]
rs.MoveNext


Loop

Thank you

George Nicholson said:
No need to count.

Set rs =
Forms("parentformname").NameOfControlContainingFirstSubform.Form.Recordset
Do Until rs.EOF
'.....copy data from rs to 2nd subform
rs.MoveNext
Loop
 
J

jb

Thank you!
It works.

George Nicholson said:
Dont copy from the form. Copy from the recordset.

Set rs = Forms("Form1").[Subform1].Form.Recordset

Do Until rs.EOF
Forms![ Form]![subform].Form![Field1] = rs![Field10]
Forms![ Form]![subform].Form![ Field2] = rs![Field20]
Forms![ Form]![subform].Form![Field3] = rs![Field30]
rs.MoveNext
Loop

--
HTH,
George


jb said:
I am using this code and it is not copying the data from first record nor
advancing to second and third records:
DoCmd.Echo True, ""
Set rs = Forms("Form1").[Subform1].Form.Recordset


Do Until rs.EOF
Forms![ Form]![subform].Form![Field1] = Forms![ Form1]![
subform1].Form![ Field10]
Forms![ Form]![subform].Form![ Field2] = Forms![ Form1]![
subform1].Form![Field20]
Forms![ Form]![subform].Form![Field3] = Forms![ Form1]![
subform1].Form![Field30]
rs.MoveNext


Loop

Thank you

George Nicholson said:
No need to count.

Set rs =
Forms("parentformname").NameOfControlContainingFirstSubform.Form.Recordset
Do Until rs.EOF
'.....copy data from rs to 2nd subform
rs.MoveNext
Loop

--
HTH,
George


In Acess 2003, I need to select the first record from a subform to copy
the
data in it to another subform with a VBA module (called from a macro
outside
both forms and subforms), and then select the next record and do the
same,
until the last record. The form/subForm that receives the data is blank
and
its a new record.
I think that the Do and Do While procedure is the correct but I can't
seem
to write the code to select the second record, the third and so on and
copy
each row data to the other subform. I think also I need a counter to
assist
in how many times to do the procedure. Can you help me? Thanks!
 

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