473,441 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 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 9219
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text field called . It gets populated based on what the user selects in a field on the...
3
by: William Wisnieski | last post by:
Hello Again, I'm really stuck on this one.....so I'm going to try a different approach to this problem. I have a query by form that returns a record set in a datasheet. The user double...
2
by: Michelle | last post by:
Hi all I have used knowledge base article 112747 to improve my subforms performance. I am using Access 97. I have a main form where i put an extra textbox which concatenated TeamID WeekNum...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
3
by: david | last post by:
Hi, I've been reading tons of posts on how to copy records, but to no avail....i'm still stuck. There are three tables: Main, Sub-Form1 & Sub-Form2 I have a form which displays some data....
1
by: John Phelan-Cummings | last post by:
I'm not certain if this made the post. Sorry if it's a repeat: Using a Button to take an autonumber from one form to populate another autonumber field on another form. I have a Mainform "A"...
3
lwwhite
by: lwwhite | last post by:
(Access 2003) Here's what I want to do: enable users to double-click a field in a datasheet-view subform and thereby save the contents of that field to the Windows clipboard so that they can then...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
0
by: carlton129 | last post by:
Hi! I am trying to copy the current form and subform to the clipboard with the click of a button so that I can paste it in another application. So far, I can get all of the Form info together into...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.