Copying data between 2 subforms

  • Thread starter Thread starter Ulcom
  • Start date Start date
U

Ulcom

I

I have a form FrmMain which contain 2 subforms SbForm1 and SbForm2

Each of the subform has the same field call N°Emp

I would like the code to put on a button and this code should be able to
copy all records on the SbForm2 to the SbForm1

I know it should exist many method to do this but I would like something
simple
thanks
 
I

I have a form FrmMain which contain 2 subforms SbForm1 and SbForm2

Each of the subform has the same field call N°Emp

I would like the code to put on a button and this code should be able to
copy all records on the SbForm2 to the SbForm1

I know it should exist many method to do this but I would like something
simple
thanks

The first thing to consider is: Subforms DO NOT CONTAIN DATA.

Tables contain data. Forms and subforms are just *windows*, tools to
work with the data stored in the tables.

The next consideration is that you should NEVER store data
redundantly. Once in a great while you might need to store the same
value in two different tables (other than a linking field), but if you
do so it's because it really IS different data that happens to have
the same value, not redundant. Mass copying records from one table to
another table is almost certainly neither necessary nor wise.

I suspect there is a better solution to the business problem you're
trying to solve! Please let us know what you're trying to accomplish,
and someone may be able to suggest a way to do so without storing data
redundantly. What are the Recordsources of your main form and
subforms? How are the tables related?

John W. Vinson[MVP]
 
Hi
I will try to explain more.

First I have a Table named TblDataDate and this table has 1 field named
DataDate . One record for each day no duplicate

I Have a second table named TblData. This table has 2 fields DataDate and
N°Emp. DataDate and N°Emp duplicate = yes

Finaly I have a query that contain only 1 field named N°Emp.


Now I have a single form named FrmData and this form is link to TblData.
There is only 1 field and it is DataDate

I have a continuous subform named FrmData1. This form is link to table
TblData and link child and master is DataDate

So let say I put 1 fev 04 in the field DataDate of main form (FrmData)
; for each record I had in continous form(FrmData1)
I don't have to put the date because this is done automatically
So I put 3 in the N°Emp field and 1 fev 04 is automatically add in the
field DataDate.

Now on the same main form I have another continuous subform named FrmResult
that contain the N°Emp that sould be added for the specific day.
I can easily do it with the mouse.

As the forms have the same fields names i just select all records
of the form FrmResult, copy them with right mouse button. then go in the
border of the new record on form FrmData1 and with the right mouse button
again click on paste and that's it.

But i would love to have a button that would transfert records from a form
to another form but more and more i think it should be more appropriate to
copy fron form and paste to the query

I don't know
thanks
 
I don't have to put the date because this is done automatically
So I put 3 in the N°Emp field and 1 fev 04 is automatically add in the
field DataDate.

Now on the same main form I have another continuous subform named FrmResult
that contain the N°Emp that sould be added for the specific day.
I can easily do it with the mouse.

I don't understand why your second form is necessary. You have already
STORED the information that N*Emp 3 was entered for 1 fev 04. Why is
it necessary to store that information, redundantly, in a second
table?

John W. Vinson[MVP]
 
Hi

Ok I have a table of employees TblEmp containing many fields. The main
field is N°Emp which is the ID number for each employee

The FrmData3 (second subform) is based on a query Qry3. This query is
based on TblEmp.

Let say I have 100 employee in TblEmp

Let say that the 01 jan 05 Qry3 (only 1 field N°Emp gives me 100
records (100 employees), I have to input 100 entries for that date. So what
I do, I copy records that are on FrmData3 (based on the query Qry3) and I
paste those records on form FrmData2 which is based on table TblData1.

The nex day 02 jan 05 , because of some criterias, Qry3 gives me only
83 employees. This time I select again all 83 records from form FrmData3 and
paste those on form FrmData2

and so on. This way, I fill table TblData1 like on day i input 100
records, next day is 83, and 91 and 94. That can can change every day.


I don't see how I could do the same with another method

thanks
 
Let say that the 01 jan 05 Qry3 (only 1 field N°Emp gives me 100
records (100 employees), I have to input 100 entries for that date. So what
I do, I copy records that are on FrmData3 (based on the query Qry3) and I
paste those records on form FrmData2 which is based on table TblData1.

The nex day 02 jan 05 , because of some criterias, Qry3 gives me only
83 employees. This time I select again all 83 records from form FrmData3 and
paste those on form FrmData2

and so on. This way, I fill table TblData1 like on day i input 100
records, next day is 83, and 91 and 94. That can can change every day.


I don't see how I could do the same with another method

What I'm asking - again! - is:

WHY is it necessary to store the information which is already
available in Qry3 into TblData1?

Perhaps it is necessary, but if it is, I do not understand WHY it is
necessary.

If you want to print out a Report - you have the needed information
already, in Qry3.

If you want to display the data on a Form - you have the needed
information already, in Qry3.

If you wish to export the data to an external file... well, that too.

What benefit do you get from storing the same information in a
separate table?

John W. Vinson[MVP]
 
Hi

FrmData is a single form and show records from table TblData which contain 1
field DataDate (date format field)

FrmData1 is a continuous subform on form FrmData it comes from TblData2
which contain 2 fields DataDate and N°Emp

Subform is related to the main form with the field DataDate

As it is in the table TblData2 that I have to store each day data, first I
want to know which employee is suppose to work. That comes from a query
related to the table TblEmp (employee's table) Of course this table has
one field named N°Emp.

Let say that out of the TblEmp I have to extract only employees who are
still working for the company for a specific day..
As I have dated fields (IN and OUT) in the TblEmp , i created a query and i
named the query Qry Data. It contain only 1 field N°Emp and the query gives
me specific records for that day
One day the query gives me 100 employees, but the next day it can gives me
95 employees if 5 of them left ort went in holiday.
So as I have to keep track for everyday, i need to add to the TblData1
records coming from the query every day because data in TblEmp can also
change everyday
So I had another continuous subform calle FrmData2
and this subform contains records from the query. Of course there are no
relations between FrmData2 and the main form.
I can easily do exactly what I want. I select all records of the form
FrmData2 (from the query). I copy the records (edit copy or mouse right
button) the I go on the other subfor (TblData1), i go at the end, right
click on the border and paste.
Next day Query give me different employees, but i just copy and paste and it
is perfect.
What I would like to do is the same but with a click on a buttton

Thanks for helping me
 
Back
Top