472,131 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,131 software developers and data experts.

Copy field from 1 subform to another

Hi all,

I have tabbed subforms where I need to copy one field value from one
subform over to another subform. Although I can run an update query to
accomplish this I would like to do it through VBA.

sub tables relationships are 1:N with the main table.

So the recods display like this in the subform:

Subform1
Record Data
1 field1
2 field1
3 field1
Subform2
Record Data
1 field1
2 field1
3 field1

What I would like to do is if I go to record#2 field1 in the first
subtable and change the data I would like to put a vba after update
statment on that field that would copy over the field value to
subtable 2, record2 field1

So the data is identical and it keeps the users from having to input
it twice.

Any ideas?

Sep 26 '07 #1
3 9072
On Sep 26, 4:59 pm, Richnep <Rich...@gmail.comwrote:
Hi all,

I have tabbed subforms where I need to copy one field value from one
subform over to another subform. Although I can run an update query to
accomplish this I would like to do it through VBA.

sub tables relationships are 1:N with the main table.

So the recods display like this in the subform:

Subform1
Record Data
1 field1
2 field1
3 field1
Subform2
Record Data
1 field1
2 field1
3 field1

What I would like to do is if I go to record#2 field1 in the first
subtable and change the data I would like to put a vba after update
statment on that field that would copy over the field value to
subtable 2, record2 field1

So the data is identical and it keeps the users from having to input
it twice.

Any ideas?
sure. read Keri Hardwick's article on referencing subform controls at
www.mvps.org The answer is there.

Sep 26 '07 #2
On Sep 26, 7:07 pm, "pietlin...@hotmail.com" <pietlin...@hotmail.com>
wrote:
On Sep 26, 4:59 pm, Richnep <Rich...@gmail.comwrote:


Hi all,
I have tabbed subforms where I need to copy one field value from one
subform over to another subform. Although I can run an update query to
accomplish this I would like to do it through VBA.
sub tables relationships are 1:N with the main table.
So the recods display like this in the subform:
Subform1
Record Data
1 field1
2 field1
3 field1
Subform2
Record Data
1 field1
2 field1
3 field1
What I would like to do is if I go to record#2 field1 in the first
subtable and change the data I would like to put a vba after update
statment on that field that would copy over the field value to
subtable 2, record2 field1
So the data is identical and it keeps the users from having to input
it twice.
Any ideas?

sure. read Keri Hardwick's article on referencing subform controls atwww.mvps.org The answer is there.- Hide quoted text -

- Show quoted text -
Thanks, I was kinda looking for some more specific direction as I am a
VBA newbie.

Sep 27 '07 #3
Richnep wrote:
On Sep 26, 7:07 pm, "pietlin...@hotmail.com" <pietlin...@hotmail.com>
wrote:
>>On Sep 26, 4:59 pm, Richnep <Rich...@gmail.comwrote:

>>>Hi all,
>>>I have tabbed subforms where I need to copy one field value from one
subform over to another subform. Although I can run an update query to
accomplish this I would like to do it through VBA.
>>>sub tables relationships are 1:N with the main table.
>>>So the recods display like this in the subform:
>>>Subform1
Record Data
1 field1
2 field1
3 field1
Subform2
Record Data
1 field1
2 field1
3 field1
>>>What I would like to do is if I go to record#2 field1 in the first
subtable and change the data I would like to put a vba after update
statment on that field that would copy over the field value to
subtable 2, record2 field1
>>>So the data is identical and it keeps the users from having to input
it twice.
>>>Any ideas?

sure. read Keri Hardwick's article on referencing subform controls atwww.mvps.org The answer is there.- Hide quoted text -

- Show quoted text -


Thanks, I was kinda looking for some more specific direction as I am a
VBA newbie.
An example of how to reference
MF = MainForm
SF1 = Subform1
SF2 = Subform2

Forms!MF!SF1!SomeTextBoxInSF1 = Forms!MF!SF2!SomeTextBoxInSF2

Of course, specifying an update of a field will require a bit more info.
You can't, for example, do
DoCmd.GoToRecord acDataForm, "SF2", 3
or
DoCmd.GoToRecord acDataForm, "Forms!MF!SF2", 3
because you are using subforms, not single forms.

You might need to access the recordset of the subform you want to
update. Let's say you have a field called SF1ID as the primary key for
Subform1. Using the AbsolutePosition you are assuring that you get the
record position of the current record in the recordset. Then scan
through the recordset to update and find that position. If you see some
stuff you don't understand below after you can highlite the word and
press F1 to get help.

AfterUpdate()
Dim rst2 As Recordset
Dim rst1 As Recordset

Set rst2 = Forms!MF!SF2.Form.RecordsetClone
Set rst1 = Forms!MF!SF1.Form.RecordsetClone

'find the current record
rst1.findfirst "SF1ID = " & Me.SF1ID

rst2.MoveFirst
Do While Not rst2.EOF
If rst2.AbsolutePosition = rst1.AbsolutePosition then
rst2.Edit
rst2!Field2Update = Me.SF1Field
rst2.Update
Exit Do
Else
rst2.MoveNext
Endif
Loop
rst1.close
rst2.close
Set rst1 = Nothing
Set rst1 = Nothing
End Sub
Sep 27 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by William Wisnieski | last post: by
3 posts views Thread by William Wisnieski | last post: by
2 posts views Thread by Michelle | last post: by
3 posts views Thread by david | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.