Iterate/loop through a form to copy value from one control to anot

R

Rick Schneider

This would seem simple but I can't seem to find a way to do it.

I have a form whose underlying query is a join between 2 tables, one with a
field "Web_Desc" (string) that is populated and the other with a field
"Web_page_Description" that I want to copy the value in the first 's field
into). In other words, I want the two fiekds to have the same value. The
only way I have found to do this is set up a recordset and cycle through it
as follows:

Private Sub Command7_Click()
Dim rs As DAO.Recordset
Dim db As Database

Set db = CurrentDb
Set rs = db.OpenRecordset("qry_web_temp")
rs.BOF
Do While Not rs.EOF
Web_page_Description = Web_Desc
MoveNext
Loop

rs.Close
db.Close

End Sub

In the form, it will complete the first record and then stop. Should this
be done outside the form? I have not worked with recordsets before and so am
confused.

Any help is greatly appreciated.
 
D

David H

So you want the value of one field to automatically default to the value of
another?

If that's the case, create two controls on the form Control1 and Control2.
Set the control source for both to the appropriate field in the underlying
recordset. Then set the .DefaultProperty of Control2 to reference Control1 as
in...

=[Forms]![formNameHere]![Control1Namehere]
 
R

Rick Schneider

David,

Thanks for the reply.

This is not what I am trying to do. I am basically creating a new table
that will include a field from an existing table, with a one to many
relationship. So I am trying to populate the new table with the original
value and the related index from the original table (the many side). That
should have been easy, but somehow did not include the field value (I screwed
it up), just the index. And since the many table has an auto increment index
itself, I thought the best way to do it (while maintaining the index of the
sub table, otherwise I could just delete the original records and append them
again) was to just iterate through and copy one field to the other. I hope
that is clear.

This can be worked around pretty easily, but always wondered how to do this,
so thought I would try to solve it and learn.

Thanks for any help.

Rick

David H said:
So you want the value of one field to automatically default to the value of
another?

If that's the case, create two controls on the form Control1 and Control2.
Set the control source for both to the appropriate field in the underlying
recordset. Then set the .DefaultProperty of Control2 to reference Control1 as
in...

=[Forms]![formNameHere]![Control1Namehere]

Rick Schneider said:
This would seem simple but I can't seem to find a way to do it.

I have a form whose underlying query is a join between 2 tables, one with a
field "Web_Desc" (string) that is populated and the other with a field
"Web_page_Description" that I want to copy the value in the first 's field
into). In other words, I want the two fiekds to have the same value. The
only way I have found to do this is set up a recordset and cycle through it
as follows:

Private Sub Command7_Click()
Dim rs As DAO.Recordset
Dim db As Database

Set db = CurrentDb
Set rs = db.OpenRecordset("qry_web_temp")
rs.BOF
Do While Not rs.EOF
Web_page_Description = Web_Desc
MoveNext
Loop

rs.Close
db.Close

End Sub

In the form, it will complete the first record and then stop. Should this
be done outside the form? I have not worked with recordsets before and so am
confused.

Any help is greatly appreciated.
 

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