Copy data from two tables

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I am using Access 2000

I have two tables: tblTransHeader and tblTransDetail
tblTransHeader has TransHeaderID (autonumber) for its
primary key
tblTransDetail has TransDetailID (autonumber) for its
primary key and a foreign key TransHeaderID to
tblTransHeader.

Each record in tblTransHeader has a field for year.

I can create a query to select all records in
tblTransHeader and related records in tblTransDetail for a
given year.

What I want to do, and am having the problem with, is take
the data selected and append to tblTransHeader and
tblTransDetail using a different year. All the data is to
remain the same in each table except for the year (and the
autonumbers and linked foreing key).

The database is used in our budgetting process and
typically contains 3 years of data (current, prior,
next . . . 2002, 2003, 2004). When we start to do next
year's budget, we currently type in manually the new
year's transactions information and details. Normally very
little changes, except for the amounts and maybe a couple
new transactions or losing a few transactions. Think the
process would be much faster if we could copy a given
year's data to a new year.

Thanks in advance for your help.

Jim
 
Well...the answer to your actual question is to use an append query to copy
the data over. Append queries can write your own numbers into the autonumber
fields.

But, let me point out that your setup does not appear to be a relational
database design. It would be a more logical design if all the data were in
the same table, using a field that has the year value in it so that you can
have separate records by year.
 
Ken,

Thanks for the help, but I still am having problems,
please keep reading.

When I use an append query, I can only select one table to
append to, not two. I would like to copy a year's worth of
TransHeader and TransDetail information to a new year, the
only thing changing is the year in TransHeader.

I could be wrong, but I believe the tables are
relational / normalize. TransHeader contains the
information related to all it's details . . . i.e. the
header may contain a salesperson information or the
information for an office lease; the details contains that
salesperson's salary, bonus, commissions, benefits, etc or
that office lease's monthly rent, occupancy costs, utility
expenses.

Maybe this might help
tblTransHeader
TransHeaderID (primary key, autonumber)
Year
Description
Type (person, lease, monthly recurring vendor, etc.)
...
tblTransDetail
TransDetailID (primary key, autonumber)
TransHeaderId (foreign key)
Comment
Account
JanAmt . . . DecAmt

I have a query to select all the right records . . .
SELECT tblTransHeader.*, tblTransDetail.*
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]![frmCopyYearSelect]!
[cboYearSelectFrom]));

I then would like to change the query from select to
append (in grid design, not sure about SQL), but can only
select one table. The year to copy to would be from
[Forms]![frmCopyYearSelect]![cboYearSelectTo]

Thanks
Jim
 
Just run two consecutive append queries. The first one for the first table,
the second one for the second table.

--
Ken Snell
<MS ACCESS MVP>

Jim said:
Ken,

Thanks for the help, but I still am having problems,
please keep reading.

When I use an append query, I can only select one table to
append to, not two. I would like to copy a year's worth of
TransHeader and TransDetail information to a new year, the
only thing changing is the year in TransHeader.

I could be wrong, but I believe the tables are
relational / normalize. TransHeader contains the
information related to all it's details . . . i.e. the
header may contain a salesperson information or the
information for an office lease; the details contains that
salesperson's salary, bonus, commissions, benefits, etc or
that office lease's monthly rent, occupancy costs, utility
expenses.

Maybe this might help
tblTransHeader
TransHeaderID (primary key, autonumber)
Year
Description
Type (person, lease, monthly recurring vendor, etc.)
...
tblTransDetail
TransDetailID (primary key, autonumber)
TransHeaderId (foreign key)
Comment
Account
JanAmt . . . DecAmt

I have a query to select all the right records . . .
SELECT tblTransHeader.*, tblTransDetail.*
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]![frmCopyYearSelect]!
[cboYearSelectFrom]));

I then would like to change the query from select to
append (in grid design, not sure about SQL), but can only
select one table. The year to copy to would be from
[Forms]![frmCopyYearSelect]![cboYearSelectTo]

Thanks
Jim


-----Original Message-----
Well...the answer to your actual question is to use an append query to copy
the data over. Append queries can write your own numbers into the autonumber
fields.

But, let me point out that your setup does not appear to be a relational
database design. It would be a more logical design if all the data were in
the same table, using a field that has the year value in it so that you can
have separate records by year.


--
Ken Snell
<MS ACCESS MVP>





.
 
Ken,

A couple more questions, please:
- Should I do tblTransHeader or tblTransDetail first
- How do I make sure that the TransHeaderID in
tblTransDetail matches the correct
tblTransHeader.TransHeaderID . . . I know that doing one
append after the other will automatically change each
tables new records ID's, but how can I make sure
tblTransDetail contains the correct TransHeaderId. Unless
I can somehow change the TransHeaderID in tblTransDetail
the new detail will point to the old header?

Thanks!
-----Original Message-----
Just run two consecutive append queries. The first one for the first table,
the second one for the second table.

--
Ken Snell
<MS ACCESS MVP>

Ken,

Thanks for the help, but I still am having problems,
please keep reading.

When I use an append query, I can only select one table to
append to, not two. I would like to copy a year's worth of
TransHeader and TransDetail information to a new year, the
only thing changing is the year in TransHeader.

I could be wrong, but I believe the tables are
relational / normalize. TransHeader contains the
information related to all it's details . . . i.e. the
header may contain a salesperson information or the
information for an office lease; the details contains that
salesperson's salary, bonus, commissions, benefits, etc or
that office lease's monthly rent, occupancy costs, utility
expenses.

Maybe this might help
tblTransHeader
TransHeaderID (primary key, autonumber)
Year
Description
Type (person, lease, monthly recurring vendor, etc.)
...
tblTransDetail
TransDetailID (primary key, autonumber)
TransHeaderId (foreign key)
Comment
Account
JanAmt . . . DecAmt

I have a query to select all the right records . . .
SELECT tblTransHeader.*, tblTransDetail.*
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]! [frmCopyYearSelect]!
[cboYearSelectFrom]));

I then would like to change the query from select to
append (in grid design, not sure about SQL), but can only
select one table. The year to copy to would be from
[Forms]![frmCopyYearSelect]![cboYearSelectTo]

Thanks
Jim


-----Original Message-----
Well...the answer to your actual question is to use an append query to copy
the data over. Append queries can write your own
numbers
into the autonumber
fields.

But, let me point out that your setup does not appear
to
be a relational
database design. It would be a more logical design if
all
the data were in
the same table, using a field that has the year value
in
it so that you can
have separate records by year.


--
Ken Snell
<MS ACCESS MVP>


I am using Access 2000

I have two tables: tblTransHeader and tblTransDetail
tblTransHeader has TransHeaderID (autonumber) for its
primary key
tblTransDetail has TransDetailID (autonumber) for its
primary key and a foreign key TransHeaderID to
tblTransHeader.

Each record in tblTransHeader has a field for year.

I can create a query to select all records in
tblTransHeader and related records in tblTransDetail for a
given year.

What I want to do, and am having the problem with, is take
the data selected and append to tblTransHeader and
tblTransDetail using a different year. All the data
is
to
remain the same in each table except for the year
(and
the
autonumbers and linked foreing key).

The database is used in our budgetting process and
typically contains 3 years of data (current, prior,
next . . . 2002, 2003, 2004). When we start to do next
year's budget, we currently type in manually the new
year's transactions information and details. Normally very
little changes, except for the amounts and maybe a couple
new transactions or losing a few transactions. Think the
process would be much faster if we could copy a given
year's data to a new year.

Thanks in advance for your help.

Jim


.


.
 
tblTransHeader is the parent table, so it should be done first. That way the
child table will find the foreign key TransHeaderID in the parent table.

With respect to the TransHeaderID value in the child table, how you set that
depends upon how you'l set the value of TransHeaderID in the parent table.
Would your first append query be using a specific value for each record's
TransHeaderID value? Or is TransHeaderID an autonumber field in the
tblTransHeader table?

--
Ken Snell
<MS ACCESS MVP>

Jim said:
Ken,

A couple more questions, please:
- Should I do tblTransHeader or tblTransDetail first
- How do I make sure that the TransHeaderID in
tblTransDetail matches the correct
tblTransHeader.TransHeaderID . . . I know that doing one
append after the other will automatically change each
tables new records ID's, but how can I make sure
tblTransDetail contains the correct TransHeaderId. Unless
I can somehow change the TransHeaderID in tblTransDetail
the new detail will point to the old header?

Thanks!
-----Original Message-----
Just run two consecutive append queries. The first one for the first table,
the second one for the second table.

--
Ken Snell
<MS ACCESS MVP>

Ken,

Thanks for the help, but I still am having problems,
please keep reading.

When I use an append query, I can only select one table to
append to, not two. I would like to copy a year's worth of
TransHeader and TransDetail information to a new year, the
only thing changing is the year in TransHeader.

I could be wrong, but I believe the tables are
relational / normalize. TransHeader contains the
information related to all it's details . . . i.e. the
header may contain a salesperson information or the
information for an office lease; the details contains that
salesperson's salary, bonus, commissions, benefits, etc or
that office lease's monthly rent, occupancy costs, utility
expenses.

Maybe this might help
tblTransHeader
TransHeaderID (primary key, autonumber)
Year
Description
Type (person, lease, monthly recurring vendor, etc.)
...
tblTransDetail
TransDetailID (primary key, autonumber)
TransHeaderId (foreign key)
Comment
Account
JanAmt . . . DecAmt

I have a query to select all the right records . . .
SELECT tblTransHeader.*, tblTransDetail.*
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]! [frmCopyYearSelect]!
[cboYearSelectFrom]));

I then would like to change the query from select to
append (in grid design, not sure about SQL), but can only
select one table. The year to copy to would be from
[Forms]![frmCopyYearSelect]![cboYearSelectTo]

Thanks
Jim



-----Original Message-----
Well...the answer to your actual question is to use an
append query to copy
the data over. Append queries can write your own numbers
into the autonumber
fields.

But, let me point out that your setup does not appear to
be a relational
database design. It would be a more logical design if all
the data were in
the same table, using a field that has the year value in
it so that you can
have separate records by year.


--
Ken Snell
<MS ACCESS MVP>


message
I am using Access 2000

I have two tables: tblTransHeader and tblTransDetail
tblTransHeader has TransHeaderID (autonumber) for its
primary key
tblTransDetail has TransDetailID (autonumber) for its
primary key and a foreign key TransHeaderID to
tblTransHeader.

Each record in tblTransHeader has a field for year.

I can create a query to select all records in
tblTransHeader and related records in tblTransDetail
for a
given year.

What I want to do, and am having the problem with, is
take
the data selected and append to tblTransHeader and
tblTransDetail using a different year. All the data is
to
remain the same in each table except for the year (and
the
autonumbers and linked foreing key).

The database is used in our budgetting process and
typically contains 3 years of data (current, prior,
next . . . 2002, 2003, 2004). When we start to do next
year's budget, we currently type in manually the new
year's transactions information and details. Normally
very
little changes, except for the amounts and maybe a
couple
new transactions or losing a few transactions. Think the
process would be much faster if we could copy a given
year's data to a new year.

Thanks in advance for your help.

Jim


.


.
 
Ken,

tblTransHeader.TransHeaderID is autonumber.

Thanks,


-----Original Message-----
tblTransHeader is the parent table, so it should be done first. That way the
child table will find the foreign key TransHeaderID in the parent table.

With respect to the TransHeaderID value in the child table, how you set that
depends upon how you'l set the value of TransHeaderID in the parent table.
Would your first append query be using a specific value for each record's
TransHeaderID value? Or is TransHeaderID an autonumber field in the
tblTransHeader table?

--
Ken Snell
<MS ACCESS MVP>

Ken,

A couple more questions, please:
- Should I do tblTransHeader or tblTransDetail first
- How do I make sure that the TransHeaderID in
tblTransDetail matches the correct
tblTransHeader.TransHeaderID . . . I know that doing one
append after the other will automatically change each
tables new records ID's, but how can I make sure
tblTransDetail contains the correct TransHeaderId. Unless
I can somehow change the TransHeaderID in tblTransDetail
the new detail will point to the old header?

Thanks!
-----Original Message-----
Just run two consecutive append queries. The first one for the first table,
the second one for the second table.

--
Ken Snell
<MS ACCESS MVP>

Ken,

Thanks for the help, but I still am having problems,
please keep reading.

When I use an append query, I can only select one
table
to
append to, not two. I would like to copy a year's
worth
of
TransHeader and TransDetail information to a new
year,
the
only thing changing is the year in TransHeader.

I could be wrong, but I believe the tables are
relational / normalize. TransHeader contains the
information related to all it's details . . . i.e. the
header may contain a salesperson information or the
information for an office lease; the details contains that
salesperson's salary, bonus, commissions, benefits,
etc
or
that office lease's monthly rent, occupancy costs, utility
expenses.

Maybe this might help
tblTransHeader
TransHeaderID (primary key, autonumber)
Year
Description
Type (person, lease, monthly recurring vendor, etc.)
...
tblTransDetail
TransDetailID (primary key, autonumber)
TransHeaderId (foreign key)
Comment
Account
JanAmt . . . DecAmt

I have a query to select all the right records . . .
SELECT tblTransHeader.*, tblTransDetail.*
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]! [frmCopyYearSelect]!
[cboYearSelectFrom]));

I then would like to change the query from select to
append (in grid design, not sure about SQL), but can only
select one table. The year to copy to would be from
[Forms]![frmCopyYearSelect]![cboYearSelectTo]

Thanks
Jim



-----Original Message-----
Well...the answer to your actual question is to use an
append query to copy
the data over. Append queries can write your own numbers
into the autonumber
fields.

But, let me point out that your setup does not
appear
to
be a relational
database design. It would be a more logical design
if
all
the data were in
the same table, using a field that has the year
value
in
it so that you can
have separate records by year.


--
Ken Snell
<MS ACCESS MVP>


message
I am using Access 2000

I have two tables: tblTransHeader and tblTransDetail
tblTransHeader has TransHeaderID (autonumber) for its
primary key
tblTransDetail has TransDetailID (autonumber) for its
primary key and a foreign key TransHeaderID to
tblTransHeader.

Each record in tblTransHeader has a field for year.

I can create a query to select all records in
tblTransHeader and related records in tblTransDetail
for a
given year.

What I want to do, and am having the problem with, is
take
the data selected and append to tblTransHeader and
tblTransDetail using a different year. All the
data
is
to
remain the same in each table except for the year (and
the
autonumbers and linked foreing key).

The database is used in our budgetting process and
typically contains 3 years of data (current, prior,
next . . . 2002, 2003, 2004). When we start to do next
year's budget, we currently type in manually the new
year's transactions information and details. Normally
very
little changes, except for the amounts and maybe a
couple
new transactions or losing a few transactions.
Think
the
process would be much faster if we could copy a given
year's data to a new year.

Thanks in advance for your help.

Jim


.



.


.
 
Assuming that you wish to continue using the same value for TransHeaderID as
was in the original tables, and assuming that the TransHeaderID field in the
table to which you're appending the data has either no records or has no
records with the same values of TransHeaderID, then your append query can be
run such that you put the current value of TransHeaderID into both tables.
An append query can be used to put your own values into an Autonumber field.

--
Ken Snell
<MS ACCESS MVP>

Jim said:
Ken,

tblTransHeader.TransHeaderID is autonumber.

Thanks,


-----Original Message-----
tblTransHeader is the parent table, so it should be done first. That way the
child table will find the foreign key TransHeaderID in the parent table.

With respect to the TransHeaderID value in the child table, how you set that
depends upon how you'l set the value of TransHeaderID in the parent table.
Would your first append query be using a specific value for each record's
TransHeaderID value? Or is TransHeaderID an autonumber field in the
tblTransHeader table?

--
Ken Snell
<MS ACCESS MVP>

Ken,

A couple more questions, please:
- Should I do tblTransHeader or tblTransDetail first
- How do I make sure that the TransHeaderID in
tblTransDetail matches the correct
tblTransHeader.TransHeaderID . . . I know that doing one
append after the other will automatically change each
tables new records ID's, but how can I make sure
tblTransDetail contains the correct TransHeaderId. Unless
I can somehow change the TransHeaderID in tblTransDetail
the new detail will point to the old header?

Thanks!

-----Original Message-----
Just run two consecutive append queries. The first one
for the first table,
the second one for the second table.

--
Ken Snell
<MS ACCESS MVP>

message
Ken,

Thanks for the help, but I still am having problems,
please keep reading.

When I use an append query, I can only select one table
to
append to, not two. I would like to copy a year's worth
of
TransHeader and TransDetail information to a new year,
the
only thing changing is the year in TransHeader.

I could be wrong, but I believe the tables are
relational / normalize. TransHeader contains the
information related to all it's details . . . i.e. the
header may contain a salesperson information or the
information for an office lease; the details contains
that
salesperson's salary, bonus, commissions, benefits, etc
or
that office lease's monthly rent, occupancy costs,
utility
expenses.

Maybe this might help
tblTransHeader
TransHeaderID (primary key, autonumber)
Year
Description
Type (person, lease, monthly recurring vendor, etc.)
...
tblTransDetail
TransDetailID (primary key, autonumber)
TransHeaderId (foreign key)
Comment
Account
JanAmt . . . DecAmt

I have a query to select all the right records . . .
SELECT tblTransHeader.*, tblTransDetail.*
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID =
tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]!
[frmCopyYearSelect]!
[cboYearSelectFrom]));

I then would like to change the query from select to
append (in grid design, not sure about SQL), but can
only
select one table. The year to copy to would be from
[Forms]![frmCopyYearSelect]![cboYearSelectTo]

Thanks
Jim



-----Original Message-----
Well...the answer to your actual question is to use an
append query to copy
the data over. Append queries can write your own
numbers
into the autonumber
fields.

But, let me point out that your setup does not appear
to
be a relational
database design. It would be a more logical design if
all
the data were in
the same table, using a field that has the year value
in
it so that you can
have separate records by year.


--
Ken Snell
<MS ACCESS MVP>


message
I am using Access 2000

I have two tables: tblTransHeader and tblTransDetail
tblTransHeader has TransHeaderID (autonumber) for its
primary key
tblTransDetail has TransDetailID (autonumber) for its
primary key and a foreign key TransHeaderID to
tblTransHeader.

Each record in tblTransHeader has a field for year.

I can create a query to select all records in
tblTransHeader and related records in tblTransDetail
for a
given year.

What I want to do, and am having the problem with, is
take
the data selected and append to tblTransHeader and
tblTransDetail using a different year. All the data
is
to
remain the same in each table except for the year
(and
the
autonumbers and linked foreing key).

The database is used in our budgetting process and
typically contains 3 years of data (current, prior,
next . . . 2002, 2003, 2004). When we start to do
next
year's budget, we currently type in manually the new
year's transactions information and details. Normally
very
little changes, except for the amounts and maybe a
couple
new transactions or losing a few transactions. Think
the
process would be much faster if we could copy a given
year's data to a new year.

Thanks in advance for your help.

Jim


.



.


.
 
Ken,

I think we are almost there (I hope). I thank you so much
for your help so far and your continued help.

I still am not completely clear about how to maintain the
correct TransHeaderID for tblTransDetail. Let me
illistrate.

Before "Copy" procedure (simplified):
tblTransHeader
TransHeaderID Year Description
1 2003 XYZ Office Complex
2 2003 SBC Communication - Phone
tblTransDetail
TransDetailID TransHeaderID Account Amount
1 1 Checking -25000
2 1 Rent 20000
3 1 Occupancy 5000
4 2 Payable -2000
5 2 Telephone 1250
6 2 Internet 750

After "Copy" procedure (simplified):
tblTransHeader
TransHeaderID Year Description
1 2003 XYZ Office Complex
2 2003 SBC Communication - Phone
3 2004 XYZ Office Complex
4 2004 SBC Communication - Phone
tblTransDetail
TransDetailID TransHeaderID Account Amount
1 1 Checking -25000
2 1 Rent 20000
3 1 Occupancy 5000
4 2 Payable -2000
5 2 Telephone 1250
6 2 Internet 750
7 3 Checking -25000
8 3 Rent 20000
9 3 Occupancy 5000
10 4 Payable -2000
11 4 Telephone 1250
12 4 Internet 750

The idea is to:
1) Be able to run reports on the budget for more than 1
year
2) Have different amounts for same transaction detail or
completely differnece transactions for any given year
3) Make setting up a new year much eaiser and accurate
than having to re-enter a new years worth of data.

I get how to do the first append query for tblTransHeader,
and mostly know how do the second append query except for
maintaining the correct TransHeaderID.

1st query:
INSERT INTO tblTransHeader ( Description, Type, Year )
SELECT tblTransHeader.Description, tblTransHeader.Type,
[Forms]![frmCopyYearSelect]![cboYearSelectTo] AS NewYear
FROM tblTransHeader
WHERE (((tblTransHeader.Year)=[Forms]![frmCopyYearSelect]!
[cboYearSelectFrom]));

2nd query:
*** This would use the "old" TransHeaderID, how do I have
it use the "new" TransHeaderID?***
INSERT INTO tblTransDetail ( TransHeaderID, Comment,
Account, JanAmt, FebAmt, MarAmt, AprAmt, JunAmt, JulAmt,
AugAmt, SepAmt, OctAmt, NovAmt, DecAmt )
SELECT tblTransDetail.TransHeaderID,
tblTransDetail.Comment, tblTransDetail.Account,
tblTransDetail.JanAmt, tblTransDetail.FebAmt,
tblTransDetail.MarAmt, tblTransDetail.AprAmt,
tblTransDetail.JunAmt, tblTransDetail.JulAmt,
tblTransDetail.AugAmt, tblTransDetail.SepAmt,
tblTransDetail.OctAmt, tblTransDetail.NovAmt,
tblTransDetail.DecAmt
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]![frmCopyYearSelect]!
[cboYearSelectFrom]));


Jim
-----Original Message-----
Assuming that you wish to continue using the same value for TransHeaderID as
was in the original tables, and assuming that the TransHeaderID field in the
table to which you're appending the data has either no records or has no
records with the same values of TransHeaderID, then your append query can be
run such that you put the current value of TransHeaderID into both tables.
An append query can be used to put your own values into an Autonumber field.

--
Ken Snell
<MS ACCESS MVP>

Ken,

tblTransHeader.TransHeaderID is autonumber.

Thanks,


-----Original Message-----
tblTransHeader is the parent table, so it should be
done
first. That way the
child table will find the foreign key TransHeaderID in the parent table.

With respect to the TransHeaderID value in the child table, how you set that
depends upon how you'l set the value of TransHeaderID
in
the parent table.
Would your first append query be using a specific value for each record's
TransHeaderID value? Or is TransHeaderID an autonumber field in the
tblTransHeader table?

--
Ken Snell
<MS ACCESS MVP>

Ken,

A couple more questions, please:
- Should I do tblTransHeader or tblTransDetail first
- How do I make sure that the TransHeaderID in
tblTransDetail matches the correct
tblTransHeader.TransHeaderID . . . I know that doing one
append after the other will automatically change each
tables new records ID's, but how can I make sure
tblTransDetail contains the correct TransHeaderId. Unless
I can somehow change the TransHeaderID in tblTransDetail
the new detail will point to the old header?

Thanks!

-----Original Message-----
Just run two consecutive append queries. The first one
for the first table,
the second one for the second table.

--
Ken Snell
<MS ACCESS MVP>

message
Ken,

Thanks for the help, but I still am having problems,
please keep reading.

When I use an append query, I can only select one table
to
append to, not two. I would like to copy a year's worth
of
TransHeader and TransDetail information to a new year,
the
only thing changing is the year in TransHeader.

I could be wrong, but I believe the tables are
relational / normalize. TransHeader contains the
information related to all it's details . . . i.e. the
header may contain a salesperson information or the
information for an office lease; the details contains
that
salesperson's salary, bonus, commissions,
benefits,
etc
or
that office lease's monthly rent, occupancy costs,
utility
expenses.

Maybe this might help
tblTransHeader
TransHeaderID (primary key, autonumber)
Year
Description
Type (person, lease, monthly recurring vendor, etc.)
...
tblTransDetail
TransDetailID (primary key, autonumber)
TransHeaderId (foreign key)
Comment
Account
JanAmt . . . DecAmt

I have a query to select all the right records . . .
SELECT tblTransHeader.*, tblTransDetail.*
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID =
tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]!
[frmCopyYearSelect]!
[cboYearSelectFrom]));

I then would like to change the query from select to
append (in grid design, not sure about SQL), but can
only
select one table. The year to copy to would be from
[Forms]![frmCopyYearSelect]![cboYearSelectTo]

Thanks
Jim



-----Original Message-----
Well...the answer to your actual question is to
use
an
append query to copy
the data over. Append queries can write your own
numbers
into the autonumber
fields.

But, let me point out that your setup does not appear
to
be a relational
database design. It would be a more logical
design
if
all
the data were in
the same table, using a field that has the year value
in
it so that you can
have separate records by year.


--
Ken Snell
<MS ACCESS MVP>


message
I am using Access 2000

I have two tables: tblTransHeader and tblTransDetail
tblTransHeader has TransHeaderID (autonumber)
for
its
primary key
tblTransDetail has TransDetailID (autonumber)
for
its
primary key and a foreign key TransHeaderID to
tblTransHeader.

Each record in tblTransHeader has a field for year.

I can create a query to select all records in
tblTransHeader and related records in tblTransDetail
for a
given year.

What I want to do, and am having the problem with, is
take
the data selected and append to tblTransHeader and
tblTransDetail using a different year. All the data
is
to
remain the same in each table except for the year
(and
the
autonumbers and linked foreing key).

The database is used in our budgetting process and
typically contains 3 years of data (current, prior,
next . . . 2002, 2003, 2004). When we start to do
next
year's budget, we currently type in manually
the
new
year's transactions information and details. Normally
very
little changes, except for the amounts and maybe a
couple
new transactions or losing a few transactions. Think
the
process would be much faster if we could copy a given
year's data to a new year.

Thanks in advance for your help.

Jim


.



.



.


.
 
OK - what you're doing here is different than what I was thinking you were
doing. The suggestion that I'd posted assumed that you would be keeping the
primary key value from the old table -- thus, you'd certainly know what that
key value was and could use it in the second append query.

However, what you're doing here (again, I reiterate my earlier note about
whether you really need to copy into new tables for each year...you can run
the reports you want even when the data are in one table...but I digress...)
is creating new primary key values. Thus, we'll need to identify what the
new primary key value is when we run the second append query.

Am I correct in assuming that the "unique" identifiers in the new
tblTransHeader table (after the primary key field) is the Year (another side
note: not good idea to use Year, Date, Month, Day, Name, Caption, etc. as
field or control names..these are special words to ACCESS -- the names of
builtin functions or properties or methods, and you can confuse ACCESS when
you use them in control or field names!) and the Description?

If yes, then what you'll need to do is to run your first append query to get
the tblTransHeader records in the table.

Then, the second query will can use a DLookup function in a calculated field
(note: this will slow down the running of the second query) in order to get
the value of the primary key from the new tblTransHeader table. Something
like this should get you close (I'm using the query that you'd posted
earlier as the starting point -- note the use of DLookup and note that I've
used a "New tblTransHeader" string as the name of the new tblTransHeader
table, as I believe you did not append via the first query into the previous
tblTransHeader table?):

INSERT INTO tblTransDetail ( TransHeaderID, Comment,
Account, JanAmt, FebAmt, MarAmt, AprAmt, JunAmt, JulAmt,
AugAmt, SepAmt, OctAmt, NovAmt, DecAmt )
SELECT (DLookup("TransHeaderID", "New tblTransHeader", "[Description] = '" &
tblTransHeader.Description & "'
And [Year] = " & [Forms]![frmCopyYearSelect]![cboYearSelectFrom])) AS THID,
tblTransDetail.Comment, tblTransDetail.Account,
tblTransDetail.JanAmt, tblTransDetail.FebAmt,
tblTransDetail.MarAmt, tblTransDetail.AprAmt,
tblTransDetail.JunAmt, tblTransDetail.JulAmt,
tblTransDetail.AugAmt, tblTransDetail.SepAmt,
tblTransDetail.OctAmt, tblTransDetail.NovAmt,
tblTransDetail.DecAmt
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]![frmCopyYearSelect]!
[cboYearSelectFrom]));


--
Ken Snell
<MS ACCESS MVP>


Jim said:
Ken,

I think we are almost there (I hope). I thank you so much
for your help so far and your continued help.

I still am not completely clear about how to maintain the
correct TransHeaderID for tblTransDetail. Let me
illistrate.

Before "Copy" procedure (simplified):
tblTransHeader
TransHeaderID Year Description
1 2003 XYZ Office Complex
2 2003 SBC Communication - Phone
tblTransDetail
TransDetailID TransHeaderID Account Amount
1 1 Checking -25000
2 1 Rent 20000
3 1 Occupancy 5000
4 2 Payable -2000
5 2 Telephone 1250
6 2 Internet 750

After "Copy" procedure (simplified):
tblTransHeader
TransHeaderID Year Description
1 2003 XYZ Office Complex
2 2003 SBC Communication - Phone
3 2004 XYZ Office Complex
4 2004 SBC Communication - Phone
tblTransDetail
TransDetailID TransHeaderID Account Amount
1 1 Checking -25000
2 1 Rent 20000
3 1 Occupancy 5000
4 2 Payable -2000
5 2 Telephone 1250
6 2 Internet 750
7 3 Checking -25000
8 3 Rent 20000
9 3 Occupancy 5000
10 4 Payable -2000
11 4 Telephone 1250
12 4 Internet 750

The idea is to:
1) Be able to run reports on the budget for more than 1
year
2) Have different amounts for same transaction detail or
completely differnece transactions for any given year
3) Make setting up a new year much eaiser and accurate
than having to re-enter a new years worth of data.

I get how to do the first append query for tblTransHeader,
and mostly know how do the second append query except for
maintaining the correct TransHeaderID.

1st query:
INSERT INTO tblTransHeader ( Description, Type, Year )
SELECT tblTransHeader.Description, tblTransHeader.Type,
[Forms]![frmCopyYearSelect]![cboYearSelectTo] AS NewYear
FROM tblTransHeader
WHERE (((tblTransHeader.Year)=[Forms]![frmCopyYearSelect]!
[cboYearSelectFrom]));

2nd query:
*** This would use the "old" TransHeaderID, how do I have
it use the "new" TransHeaderID?***
INSERT INTO tblTransDetail ( TransHeaderID, Comment,
Account, JanAmt, FebAmt, MarAmt, AprAmt, JunAmt, JulAmt,
AugAmt, SepAmt, OctAmt, NovAmt, DecAmt )
SELECT tblTransDetail.TransHeaderID,
tblTransDetail.Comment, tblTransDetail.Account,
tblTransDetail.JanAmt, tblTransDetail.FebAmt,
tblTransDetail.MarAmt, tblTransDetail.AprAmt,
tblTransDetail.JunAmt, tblTransDetail.JulAmt,
tblTransDetail.AugAmt, tblTransDetail.SepAmt,
tblTransDetail.OctAmt, tblTransDetail.NovAmt,
tblTransDetail.DecAmt
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]![frmCopyYearSelect]!
[cboYearSelectFrom]));


Jim
-----Original Message-----
Assuming that you wish to continue using the same value for TransHeaderID as
was in the original tables, and assuming that the TransHeaderID field in the
table to which you're appending the data has either no records or has no
records with the same values of TransHeaderID, then your append query can be
run such that you put the current value of TransHeaderID into both tables.
An append query can be used to put your own values into an Autonumber field.

--
Ken Snell
<MS ACCESS MVP>

Ken,

tblTransHeader.TransHeaderID is autonumber.

Thanks,



-----Original Message-----
tblTransHeader is the parent table, so it should be done
first. That way the
child table will find the foreign key TransHeaderID in
the parent table.

With respect to the TransHeaderID value in the child
table, how you set that
depends upon how you'l set the value of TransHeaderID in
the parent table.
Would your first append query be using a specific value
for each record's
TransHeaderID value? Or is TransHeaderID an autonumber
field in the
tblTransHeader table?

--
Ken Snell
<MS ACCESS MVP>

message
Ken,

A couple more questions, please:
- Should I do tblTransHeader or tblTransDetail first
- How do I make sure that the TransHeaderID in
tblTransDetail matches the correct
tblTransHeader.TransHeaderID . . . I know that doing one
append after the other will automatically change each
tables new records ID's, but how can I make sure
tblTransDetail contains the correct TransHeaderId.
Unless
I can somehow change the TransHeaderID in tblTransDetail
the new detail will point to the old header?

Thanks!

-----Original Message-----
Just run two consecutive append queries. The first one
for the first table,
the second one for the second table.

--
Ken Snell
<MS ACCESS MVP>

message
Ken,

Thanks for the help, but I still am having problems,
please keep reading.

When I use an append query, I can only select one
table
to
append to, not two. I would like to copy a year's
worth
of
TransHeader and TransDetail information to a new
year,
the
only thing changing is the year in TransHeader.

I could be wrong, but I believe the tables are
relational / normalize. TransHeader contains the
information related to all it's details . . . i.e.
the
header may contain a salesperson information or the
information for an office lease; the details contains
that
salesperson's salary, bonus, commissions, benefits,
etc
or
that office lease's monthly rent, occupancy costs,
utility
expenses.

Maybe this might help
tblTransHeader
TransHeaderID (primary key, autonumber)
Year
Description
Type (person, lease, monthly recurring vendor,
etc.)
...
tblTransDetail
TransDetailID (primary key, autonumber)
TransHeaderId (foreign key)
Comment
Account
JanAmt . . . DecAmt

I have a query to select all the right records . . .
SELECT tblTransHeader.*, tblTransDetail.*
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID =
tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]!
[frmCopyYearSelect]!
[cboYearSelectFrom]));

I then would like to change the query from select to
append (in grid design, not sure about SQL), but can
only
select one table. The year to copy to would be from
[Forms]![frmCopyYearSelect]![cboYearSelectTo]

Thanks
Jim



-----Original Message-----
Well...the answer to your actual question is to use
an
append query to copy
the data over. Append queries can write your own
numbers
into the autonumber
fields.

But, let me point out that your setup does not
appear
to
be a relational
database design. It would be a more logical design
if
all
the data were in
the same table, using a field that has the year
value
in
it so that you can
have separate records by year.


--
Ken Snell
<MS ACCESS MVP>


message
I am using Access 2000

I have two tables: tblTransHeader and
tblTransDetail
tblTransHeader has TransHeaderID (autonumber) for
its
primary key
tblTransDetail has TransDetailID (autonumber) for
its
primary key and a foreign key TransHeaderID to
tblTransHeader.

Each record in tblTransHeader has a field for
year.

I can create a query to select all records in
tblTransHeader and related records in
tblTransDetail
for a
given year.

What I want to do, and am having the problem
with, is
take
the data selected and append to tblTransHeader and
tblTransDetail using a different year. All the
data
is
to
remain the same in each table except for the year
(and
the
autonumbers and linked foreing key).

The database is used in our budgetting process and
typically contains 3 years of data (current,
prior,
next . . . 2002, 2003, 2004). When we start to do
next
year's budget, we currently type in manually the
new
year's transactions information and details.
Normally
very
little changes, except for the amounts and maybe a
couple
new transactions or losing a few transactions.
Think
the
process would be much faster if we could copy a
given
year's data to a new year.

Thanks in advance for your help.

Jim


.



.



.


.
 
Ken,

THANK YOU!

Using your query (with a small mod...copying to same
table and using a third criteria in "matching") seems to
work great on my test database. I am going to come in
this weekend and update the live database (of course, I
will have a backup) and make sure it works. I will post
back and let you know the results.

I agree with you that the field name probably should not
be Year, but I inheireted this database from a previous
programmer. For the moment, I am leaving as is and being
extra careful on how I use the name (bracketing
everything as needed).

Once again, thank you so much!

Jim
-----Original Message-----
OK - what you're doing here is different than what I was thinking you were
doing. The suggestion that I'd posted assumed that you would be keeping the
primary key value from the old table -- thus, you'd certainly know what that
key value was and could use it in the second append query.

However, what you're doing here (again, I reiterate my earlier note about
whether you really need to copy into new tables for each year...you can run
the reports you want even when the data are in one table...but I digress...)
is creating new primary key values. Thus, we'll need to identify what the
new primary key value is when we run the second append query.

Am I correct in assuming that the "unique" identifiers in the new
tblTransHeader table (after the primary key field) is the Year (another side
note: not good idea to use Year, Date, Month, Day, Name, Caption, etc. as
field or control names..these are special words to ACCESS -- the names of
builtin functions or properties or methods, and you can confuse ACCESS when
you use them in control or field names!) and the Description?

If yes, then what you'll need to do is to run your first append query to get
the tblTransHeader records in the table.

Then, the second query will can use a DLookup function in a calculated field
(note: this will slow down the running of the second query) in order to get
the value of the primary key from the new tblTransHeader table. Something
like this should get you close (I'm using the query that you'd posted
earlier as the starting point -- note the use of DLookup and note that I've
used a "New tblTransHeader" string as the name of the new tblTransHeader
table, as I believe you did not append via the first query into the previous
tblTransHeader table?):

INSERT INTO tblTransDetail ( TransHeaderID, Comment,
Account, JanAmt, FebAmt, MarAmt, AprAmt, JunAmt, JulAmt,
AugAmt, SepAmt, OctAmt, NovAmt, DecAmt )
SELECT (DLookup("TransHeaderID", "New
tblTransHeader", "[Description] = '" &
tblTransHeader.Description & "'
And [Year] = " & [Forms]![frmCopyYearSelect]! [cboYearSelectFrom])) AS THID,
tblTransDetail.Comment, tblTransDetail.Account,
tblTransDetail.JanAmt, tblTransDetail.FebAmt,
tblTransDetail.MarAmt, tblTransDetail.AprAmt,
tblTransDetail.JunAmt, tblTransDetail.JulAmt,
tblTransDetail.AugAmt, tblTransDetail.SepAmt,
tblTransDetail.OctAmt, tblTransDetail.NovAmt,
tblTransDetail.DecAmt
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]! [frmCopyYearSelect]!
[cboYearSelectFrom]));


--
Ken Snell
<MS ACCESS MVP>


Ken,

I think we are almost there (I hope). I thank you so much
for your help so far and your continued help.

I still am not completely clear about how to maintain the
correct TransHeaderID for tblTransDetail. Let me
illistrate.

Before "Copy" procedure (simplified):
tblTransHeader
TransHeaderID Year Description
1 2003 XYZ Office Complex
2 2003 SBC Communication - Phone
tblTransDetail
TransDetailID TransHeaderID Account Amount
1 1 Checking -25000
2 1 Rent 20000
3 1 Occupancy 5000
4 2 Payable -2000
5 2 Telephone 1250
6 2 Internet 750

After "Copy" procedure (simplified):
tblTransHeader
TransHeaderID Year Description
1 2003 XYZ Office Complex
2 2003 SBC Communication - Phone
3 2004 XYZ Office Complex
4 2004 SBC Communication - Phone
tblTransDetail
TransDetailID TransHeaderID Account Amount
1 1 Checking -25000
2 1 Rent 20000
3 1 Occupancy 5000
4 2 Payable -2000
5 2 Telephone 1250
6 2 Internet 750
7 3 Checking -25000
8 3 Rent 20000
9 3 Occupancy 5000
10 4 Payable -2000
11 4 Telephone 1250
12 4 Internet 750

The idea is to:
1) Be able to run reports on the budget for more than 1
year
2) Have different amounts for same transaction detail or
completely differnece transactions for any given year
3) Make setting up a new year much eaiser and accurate
than having to re-enter a new years worth of data.

I get how to do the first append query for tblTransHeader,
and mostly know how do the second append query except for
maintaining the correct TransHeaderID.

1st query:
INSERT INTO tblTransHeader ( Description, Type, Year )
SELECT tblTransHeader.Description, tblTransHeader.Type,
[Forms]![frmCopyYearSelect]![cboYearSelectTo] AS NewYear
FROM tblTransHeader
WHERE (((tblTransHeader.Year)=[Forms]! [frmCopyYearSelect]!
[cboYearSelectFrom]));

2nd query:
*** This would use the "old" TransHeaderID, how do I have
it use the "new" TransHeaderID?***
INSERT INTO tblTransDetail ( TransHeaderID, Comment,
Account, JanAmt, FebAmt, MarAmt, AprAmt, JunAmt, JulAmt,
AugAmt, SepAmt, OctAmt, NovAmt, DecAmt )
SELECT tblTransDetail.TransHeaderID,
tblTransDetail.Comment, tblTransDetail.Account,
tblTransDetail.JanAmt, tblTransDetail.FebAmt,
tblTransDetail.MarAmt, tblTransDetail.AprAmt,
tblTransDetail.JunAmt, tblTransDetail.JulAmt,
tblTransDetail.AugAmt, tblTransDetail.SepAmt,
tblTransDetail.OctAmt, tblTransDetail.NovAmt,
tblTransDetail.DecAmt
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]! [frmCopyYearSelect]!
[cboYearSelectFrom]));


Jim
-----Original Message-----
Assuming that you wish to continue using the same
value
for TransHeaderID as
was in the original tables, and assuming that the TransHeaderID field in the
table to which you're appending the data has either no records or has no
records with the same values of TransHeaderID, then
your
append query can be
run such that you put the current value of
TransHeaderID
into both tables.
An append query can be used to put your own values
into
an Autonumber field.
--
Ken Snell
<MS ACCESS MVP>

Ken,

tblTransHeader.TransHeaderID is autonumber.

Thanks,



-----Original Message-----
tblTransHeader is the parent table, so it should be done
first. That way the
child table will find the foreign key TransHeaderID in
the parent table.

With respect to the TransHeaderID value in the child
table, how you set that
depends upon how you'l set the value of
TransHeaderID
in
the parent table.
Would your first append query be using a specific value
for each record's
TransHeaderID value? Or is TransHeaderID an autonumber
field in the
tblTransHeader table?

--
Ken Snell
<MS ACCESS MVP>

message
Ken,

A couple more questions, please:
- Should I do tblTransHeader or tblTransDetail first
- How do I make sure that the TransHeaderID in
tblTransDetail matches the correct
tblTransHeader.TransHeaderID . . . I know that
doing
one
append after the other will automatically change each
tables new records ID's, but how can I make sure
tblTransDetail contains the correct TransHeaderId.
Unless
I can somehow change the TransHeaderID in tblTransDetail
the new detail will point to the old header?

Thanks!

-----Original Message-----
Just run two consecutive append queries. The
first
one
for the first table,
the second one for the second table.

--
Ken Snell
<MS ACCESS MVP>

message
Ken,

Thanks for the help, but I still am having problems,
please keep reading.

When I use an append query, I can only select one
table
to
append to, not two. I would like to copy a year's
worth
of
TransHeader and TransDetail information to a new
year,
the
only thing changing is the year in TransHeader.

I could be wrong, but I believe the tables are
relational / normalize. TransHeader contains the
information related to all it's details . . . i.e.
the
header may contain a salesperson information
or
the
information for an office lease; the details contains
that
salesperson's salary, bonus, commissions, benefits,
etc
or
that office lease's monthly rent, occupancy costs,
utility
expenses.

Maybe this might help
tblTransHeader
TransHeaderID (primary key, autonumber)
Year
Description
Type (person, lease, monthly recurring vendor,
etc.)
...
tblTransDetail
TransDetailID (primary key, autonumber)
TransHeaderId (foreign key)
Comment
Account
JanAmt . . . DecAmt

I have a query to select all the right records . . .
SELECT tblTransHeader.*, tblTransDetail.*
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID =
tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]!
[frmCopyYearSelect]!
[cboYearSelectFrom]));

I then would like to change the query from
select
to
append (in grid design, not sure about SQL),
but
can
only
select one table. The year to copy to would be from
[Forms]![frmCopyYearSelect]![cboYearSelectTo]

Thanks
Jim



-----Original Message-----
Well...the answer to your actual question is
to
use
an
append query to copy
the data over. Append queries can write your own
numbers
into the autonumber
fields.

But, let me point out that your setup does not
appear
to
be a relational
database design. It would be a more logical design
if
all
the data were in
the same table, using a field that has the year
value
in
it so that you can
have separate records by year.


--
Ken Snell
<MS ACCESS MVP>


message
[email protected]...
I am using Access 2000

I have two tables: tblTransHeader and
tblTransDetail
tblTransHeader has TransHeaderID
(autonumber)
for
its
primary key
tblTransDetail has TransDetailID
(autonumber)
for
its
primary key and a foreign key TransHeaderID to
tblTransHeader.

Each record in tblTransHeader has a field for
year.

I can create a query to select all records in
tblTransHeader and related records in
tblTransDetail
for a
given year.

What I want to do, and am having the problem
with, is
take
the data selected and append to
tblTransHeader
and
tblTransDetail using a different year. All the
data
is
to
remain the same in each table except for
the
year
(and
the
autonumbers and linked foreing key).

The database is used in our budgetting
process
and
typically contains 3 years of data (current,
prior,
next . . . 2002, 2003, 2004). When we
start to
do
next
year's budget, we currently type in
manually
the
new
year's transactions information and details.
Normally
very
little changes, except for the amounts and maybe a
couple
new transactions or losing a few transactions.
Think
the
process would be much faster if we could copy a
given
year's data to a new year.

Thanks in advance for your help.

Jim


.



.



.



.


.
 
You're welcome. Good luck.

--
Ken Snell
<MS ACCESS MVP>

Jim said:
Ken,

THANK YOU!

Using your query (with a small mod...copying to same
table and using a third criteria in "matching") seems to
work great on my test database. I am going to come in
this weekend and update the live database (of course, I
will have a backup) and make sure it works. I will post
back and let you know the results.

I agree with you that the field name probably should not
be Year, but I inheireted this database from a previous
programmer. For the moment, I am leaving as is and being
extra careful on how I use the name (bracketing
everything as needed).

Once again, thank you so much!

Jim
-----Original Message-----
OK - what you're doing here is different than what I was thinking you were
doing. The suggestion that I'd posted assumed that you would be keeping the
primary key value from the old table -- thus, you'd certainly know what that
key value was and could use it in the second append query.

However, what you're doing here (again, I reiterate my earlier note about
whether you really need to copy into new tables for each year...you can run
the reports you want even when the data are in one table...but I digress...)
is creating new primary key values. Thus, we'll need to identify what the
new primary key value is when we run the second append query.

Am I correct in assuming that the "unique" identifiers in the new
tblTransHeader table (after the primary key field) is the Year (another side
note: not good idea to use Year, Date, Month, Day, Name, Caption, etc. as
field or control names..these are special words to ACCESS -- the names of
builtin functions or properties or methods, and you can confuse ACCESS when
you use them in control or field names!) and the Description?

If yes, then what you'll need to do is to run your first append query to get
the tblTransHeader records in the table.

Then, the second query will can use a DLookup function in a calculated field
(note: this will slow down the running of the second query) in order to get
the value of the primary key from the new tblTransHeader table. Something
like this should get you close (I'm using the query that you'd posted
earlier as the starting point -- note the use of DLookup and note that I've
used a "New tblTransHeader" string as the name of the new tblTransHeader
table, as I believe you did not append via the first query into the previous
tblTransHeader table?):

INSERT INTO tblTransDetail ( TransHeaderID, Comment,
Account, JanAmt, FebAmt, MarAmt, AprAmt, JunAmt, JulAmt,
AugAmt, SepAmt, OctAmt, NovAmt, DecAmt )
SELECT (DLookup("TransHeaderID", "New
tblTransHeader", "[Description] = '" &
tblTransHeader.Description & "'
And [Year] = " & [Forms]![frmCopyYearSelect]! [cboYearSelectFrom])) AS THID,
tblTransDetail.Comment, tblTransDetail.Account,
tblTransDetail.JanAmt, tblTransDetail.FebAmt,
tblTransDetail.MarAmt, tblTransDetail.AprAmt,
tblTransDetail.JunAmt, tblTransDetail.JulAmt,
tblTransDetail.AugAmt, tblTransDetail.SepAmt,
tblTransDetail.OctAmt, tblTransDetail.NovAmt,
tblTransDetail.DecAmt
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]! [frmCopyYearSelect]!
[cboYearSelectFrom]));


--
Ken Snell
<MS ACCESS MVP>


Ken,

I think we are almost there (I hope). I thank you so much
for your help so far and your continued help.

I still am not completely clear about how to maintain the
correct TransHeaderID for tblTransDetail. Let me
illistrate.

Before "Copy" procedure (simplified):
tblTransHeader
TransHeaderID Year Description
1 2003 XYZ Office Complex
2 2003 SBC Communication - Phone
tblTransDetail
TransDetailID TransHeaderID Account Amount
1 1 Checking -25000
2 1 Rent 20000
3 1 Occupancy 5000
4 2 Payable -2000
5 2 Telephone 1250
6 2 Internet 750

After "Copy" procedure (simplified):
tblTransHeader
TransHeaderID Year Description
1 2003 XYZ Office Complex
2 2003 SBC Communication - Phone
3 2004 XYZ Office Complex
4 2004 SBC Communication - Phone
tblTransDetail
TransDetailID TransHeaderID Account Amount
1 1 Checking -25000
2 1 Rent 20000
3 1 Occupancy 5000
4 2 Payable -2000
5 2 Telephone 1250
6 2 Internet 750
7 3 Checking -25000
8 3 Rent 20000
9 3 Occupancy 5000
10 4 Payable -2000
11 4 Telephone 1250
12 4 Internet 750

The idea is to:
1) Be able to run reports on the budget for more than 1
year
2) Have different amounts for same transaction detail or
completely differnece transactions for any given year
3) Make setting up a new year much eaiser and accurate
than having to re-enter a new years worth of data.

I get how to do the first append query for tblTransHeader,
and mostly know how do the second append query except for
maintaining the correct TransHeaderID.

1st query:
INSERT INTO tblTransHeader ( Description, Type, Year )
SELECT tblTransHeader.Description, tblTransHeader.Type,
[Forms]![frmCopyYearSelect]![cboYearSelectTo] AS NewYear
FROM tblTransHeader
WHERE (((tblTransHeader.Year)=[Forms]! [frmCopyYearSelect]!
[cboYearSelectFrom]));

2nd query:
*** This would use the "old" TransHeaderID, how do I have
it use the "new" TransHeaderID?***
INSERT INTO tblTransDetail ( TransHeaderID, Comment,
Account, JanAmt, FebAmt, MarAmt, AprAmt, JunAmt, JulAmt,
AugAmt, SepAmt, OctAmt, NovAmt, DecAmt )
SELECT tblTransDetail.TransHeaderID,
tblTransDetail.Comment, tblTransDetail.Account,
tblTransDetail.JanAmt, tblTransDetail.FebAmt,
tblTransDetail.MarAmt, tblTransDetail.AprAmt,
tblTransDetail.JunAmt, tblTransDetail.JulAmt,
tblTransDetail.AugAmt, tblTransDetail.SepAmt,
tblTransDetail.OctAmt, tblTransDetail.NovAmt,
tblTransDetail.DecAmt
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID = tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]! [frmCopyYearSelect]!
[cboYearSelectFrom]));


Jim

-----Original Message-----
Assuming that you wish to continue using the same value
for TransHeaderID as
was in the original tables, and assuming that the
TransHeaderID field in the
table to which you're appending the data has either no
records or has no
records with the same values of TransHeaderID, then your
append query can be
run such that you put the current value of TransHeaderID
into both tables.
An append query can be used to put your own values into
an Autonumber field.

--
Ken Snell
<MS ACCESS MP>

message
Ken,

tblTransHeader.TransHeaderID is autonumber.

Thanks,



-----Original Message-----
tblTransHeader is the parent table, so it should be
done
first. That way the
child table will find the foreign key TransHeaderID in
the parent table.

With respect to the TransHeaderID value in the child
table, how you set that
depends upon how you'l set the value of TransHeaderID
in
the parent table.
Would your first append query be using a specific value
for each record's
TransHeaderID value? Or is TransHeaderID an autonumber
field in the
tblTransHeader table?

--
Ken Snell
<MS ACCESS MVP>

message
Ken,

A couple more questions, please:
- Should I do tblTransHeader or tblTransDetail first
- How do I make sure that the TransHeaderID in
tblTransDetail matches the correct
tblTransHeader.TransHeaderID . . . I know that doing
one
append after the other will automatically change each
tables new records ID's, but how can I make sure
tblTransDetail contains the correct TransHeaderId.
Unless
I can somehow change the TransHeaderID in
tblTransDetail
the new detail will point to the old header?

Thanks!

-----Original Message-----
Just run two consecutive append queries. The first
one
for the first table,
the second one for the second table.

--
Ken Snell
<MS ACCESS MVP>

message
Ken,

Thanks for the help, but I still am having
problems,
please keep reading.

When I use an append query, I can only select one
table
to
append to, not two. I would like to copy a year's
worth
of
TransHeader and TransDetail information to a new
year,
the
only thing changing is the year in TransHeader.

I could be wrong, but I believe the tables are
relational / normalize. TransHeader contains the
information related to all it's details . . . i.e.
the
header may contain a salesperson information or
the
information for an office lease; the details
contains
that
salesperson's salary, bonus, commissions,
benefits,
etc
or
that office lease's monthly rent, occupancy costs,
utility
expenses.

Maybe this might help
tblTransHeader
TransHeaderID (primary key, autonumber)
Year
Description
Type (person, lease, monthly recurring vendor,
etc.)
...
tblTransDetail
TransDetailID (primary key, autonumber)
TransHeaderId (foreign key)
Comment
Account
JanAmt . . . DecAmt

I have a query to select all the right
records . . .
SELECT tblTransHeader.*, tblTransDetail.*
FROM tblTransDetail INNER JOIN tblTransHeader ON
tblTransDetail.TransHeaderID =
tblTransHeader.TransHeaderID
WHERE (((tblTransHeader.Year)=[Forms]!
[frmCopyYearSelect]!
[cboYearSelectFrom]));

I then would like to change the query from select
to
append (in grid design, not sure about SQL), but
can
only
select one table. The year to copy to would be
from
[Forms]![frmCopyYearSelect]![cboYearSelectTo]

Thanks
Jim



-----Original Message-----
Well...the answer to your actual question is to
use
an
append query to copy
the data over. Append queries can write your own
numbers
into the autonumber
fields.

But, let me point out that your setup does not
appear
to
be a relational
database design. It would be a more logical
design
if
all
the data were in
the same table, using a field that has the year
value
in
it so that you can
have separate records by year.


--
Ken Snell
<MS ACCESS MVP>


"Jim" <[email protected]>
wrote in
message
[email protected]...
I am using Access 2000

I have two tables: tblTransHeader and
tblTransDetail
tblTransHeader has TransHeaderID (autonumber)
for
its
primary key
tblTransDetail has TransDetailID (autonumber)
for
its
primary key and a foreign key TransHeaderID to
tblTransHeader.

Each record in tblTransHeader has a field for
year.

I can create a query to select all records in
tblTransHeader and related records in
tblTransDetail
for a
given year.

What I want to do, and am having the problem
with, is
take
the data selected and append to tblTransHeader
and
tblTransDetail using a different year. All the
data
is
to
remain the same in each table except for the
year
(and
the
autonumbers and linked foreing key).

The database is used in our budgetting process
and
typically contains 3 years of data (current,
prior,
next . . . 2002, 2003, 2004). When we start to
do
next
year's budget, we currently type in manually
the
new
year's transactions information and details.
Normally
very
little changes, except for the amounts and
maybe a
couple
new transactions or losing a few transactions.
Think
the
process would be much faster if we could copy a
given
year's data to a new year.

Thanks in advance for your help.

Jim


.



.



.



.


.
 
Back
Top