473,395 Members | 1,401 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,395 software developers and data experts.

help with copying data from one table to another

daD
I'm trying to write a small database that tracks people coming and
going from a small campground. I need to have the current guests in
the "current" table" and then have the ability to check them out to
the "archive" table when they leave, by pushing the "check-out"
button. I see the steps as follows:

1. When the check-out button is pressed, the computer should
automatically add the current date into the "date checked-out" field.

The computer should then ask "are you sure?"

2. If the answer is "yes", then the computer should automatically
move the whole record from the "current" table to the "archive"
table.

If the answer is "no", then the computer should ease the date written
into the "date checked-out" field".

I am using Access 2003. I realize this is probably a macro, but I
guess it's beyond me. I need some real talent to help me. Any help
is greatly appreciated.
James
Sep 3 '06 #1
8 3323
Why not just leave all the data in the same table and include a
CheckOutDate field? then your query would be something like

'--- untested code...

private sub cmdArchiveData()

dim intReply as integer '--- somewhere to stuff the response from the
MsgBox function.

intReply=MsgBox("Are you sure you want to archive this
record?",vbYesNo,"You're about to archive this record...")

if intReply=vbYes then
'---update only the current record on the form...
CurrentDB.Execute "UPDATE tblReservation SET CheckOutDate = Now
WHERE tblReservation.ReservationID=" &
Forms![MyForm]![txtReservationID]
end if

end sub

Sep 3 '06 #2
Moving a record to another table consists of executing an Append query (to
add it to the other table), followed by a Delete query. The code you need to
achieve this is explained in this article:
Archive: Move records to another table
at:
http://allenbrowne.com/ser-37.html

However, it seems to me that this is not a relational design. Presumably you
have clients (who could come back some day), and lots (sections of the
camping), and you assign a lot to a client for a brief period. This suggests
3 tables:
Client (one record for each hirer) with fields:
ClientID AutoNumber
Surname Text family name
FirstName Text Christian name of the responsible person
Address Text person's home address
...

Lot (one record for each lot in your camping ground). Fields:
LotID Number
...

Hiring (one record for each time a client rents a lot.) Fields:
LotID Number which lot was hired
ClientID Number which client hired it
FirstNight Date/Time first night of this booking
FinalNight Date/Time last night of booking

Advantages of this approach:
- Client only has to be entered once, even if they have multiple bookings.
- Easy to query usage (history of a lot, what's available when.)
- No need to move records into another table.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"daD" <JA********@COX.NETwrote in message
news:ab********************************@4ax.com...
I'm trying to write a small database that tracks people coming and
going from a small campground. I need to have the current guests in
the "current" table" and then have the ability to check them out to
the "archive" table when they leave, by pushing the "check-out"
button. I see the steps as follows:

1. When the check-out button is pressed, the computer should
automatically add the current date into the "date checked-out" field.

The computer should then ask "are you sure?"

2. If the answer is "yes", then the computer should automatically
move the whole record from the "current" table to the "archive"
table.

If the answer is "no", then the computer should ease the date written
into the "date checked-out" field".

I am using Access 2003. I realize this is probably a macro, but I
guess it's beyond me. I need some real talent to help me. Any help
is greatly appreciated.
James

Sep 3 '06 #3
daD
Sorry, should have mentioned that the former owner already had a
database built in access 2000 that has thousands of former customers.
I don't like this database, which is why i am trying to craete a new
one. This customer base is importnat to me for marketing efforts,
etc. I want to import that past data into my "archive" table and
query from there to support a direct marketing campaign designed to
lure former guests back for another stay. However, we're talking
about close to 20,000 people, so I don't want them cluttering up the
"curent" table, which only has a max numner 0f 812 (the number of
camping spots) That is why I need to copy from table to table.
Thanks so much for your help, Mr. Browne and everyone else who
answered.

James
On Sun, 3 Sep 2006 12:03:17 +0800, "Allen Browne"
<Al*********@SeeSig.Invalidwrote:
>Moving a record to another table consists of executing an Append query (to
add it to the other table), followed by a Delete query. The code you need to
achieve this is explained in this article:
Archive: Move records to another table
at:
http://allenbrowne.com/ser-37.html

However, it seems to me that this is not a relational design. Presumably you
have clients (who could come back some day), and lots (sections of the
camping), and you assign a lot to a client for a brief period. This suggests
3 tables:
Client (one record for each hirer) with fields:
ClientID AutoNumber
Surname Text family name
FirstName Text Christian name of the responsible person
Address Text person's home address
...

Lot (one record for each lot in your camping ground). Fields:
LotID Number
...

Hiring (one record for each time a client rents a lot.) Fields:
LotID Number which lot was hired
ClientID Number which client hired it
FirstNight Date/Time first night of this booking
FinalNight Date/Time last night of booking

Advantages of this approach:
- Client only has to be entered once, even if they have multiple bookings.
- Easy to query usage (history of a lot, what's available when.)
- No need to move records into another table.
Sep 3 '06 #4
If you design your database right and load only the records you need,
then the 20K records is largely immaterial. As a general rule, don't
base forms directly off tables. Especially if you're sharing the
backend across a network. The peformance will be horrible. If I were
you, I would create a new database and normalize first and then deal
with archived data. you could move it to an "archive" table, but then
you could just as easily base your form on a query...

SELECT <field>, <field>...
FROM <mytable>
WHERE MyTable.Archive=False

or some such thing that just essentially hides the archived data.
Otherwise, you have to muck with union queries, and that's not fun.

Sep 5 '06 #5
daD
OK, I think I am on the right track. All the forms are planned to be
based on queries off the 'current" table, except the 'past guests"
form, which is based off a query of the "archive" table, so I can see
who has stayed with us in the past.

i also have a need to know how many people are in the campground each
day. I would like the databse to run a query every day at maybe 8:00
(it should be the same time every day and should be automated) in the
morning and count the number of camping spaces that were occupied and
then store that number somewhere for later use. At the end of the
month I could run a report that lists that number for each day like:

1 800
2 799
3 811

Something simple like that. Is using a temporary table the way to go?
Something I could erase every month and start the whole thing over
again?

I have also been toying with the idea of using a web page as the
front-end. I think that there is so much more frredom in the design
with a web page and a lot of resources for graphics, etc.... Has
anyone ever done anything like that, or do you know of any utilities
that would make it easier to really make it look nice? Access seems a
littel short in that area. i guess I could design the background for
the forms in Frontpage or Photoshop and then put the fields in the
forground. Basically, I want my users accessing the database through
a browser, even though the whole thing (front-end and back-end) would
stay on my network. Tthanks agian to all you great people for sharing
your knowledge!

On 4 Sep 2006 21:09:41 -0700, pi********@hotmail.com wrote:
>If you design your database right and load only the records you need,
then the 20K records is largely immaterial. As a general rule, don't
base forms directly off tables. Especially if you're sharing the
backend across a network. The peformance will be horrible. If I were
you, I would create a new database and normalize first and then deal
with archived data. you could move it to an "archive" table, but then
you could just as easily base your form on a query...

SELECT <field>, <field>...
FROM <mytable>
WHERE MyTable.Archive=False

or some such thing that just essentially hides the archived data.
Otherwise, you have to muck with union queries, and that's not fun.
Sep 6 '06 #6

daD wrote:
OK, I think I am on the right track. All the forms are planned to be
based on queries off the 'current" table, except the 'past guests"
form, which is based off a query of the "archive" table, so I can see
who has stayed with us in the past.

i also have a need to know how many people are in the campground each
day. I would like the databse to run a query every day at maybe 8:00
(it should be the same time every day and should be automated) in the
morning and count the number of camping spaces that were occupied and
then store that number somewhere for later use.
On the right track? if you're thinking of putting all this calculated
junk in a table, I'd beg to differ. If you base your forms off queries
and your tables are properly indexed, and you only pull the data you
need from each table, then who cares how many records are in your
tables? Why not just query the live data? The query is a little
weird, but once you have it, you're there. I think storing all this
junk is a waste of space and time, unless you really need it for
querying later and you have so many records that querying the whole
dataset is unwieldy.

Sep 6 '06 #7
daD
OK, OK. Maybe not on the right track? I just need to know how many
camping sites were occupied on a given day and I thought I should
check that number at the same time every day to establish a standard.
This helps me establiush a trend of high occupancy times of the year
and low occupancy times of the year. Maybe I can offer incentives
during the slow months to lure customers in. How else would I be able
to get this info? You said somnething about indexes? I want to do it
the easiest way possible obviously, but I really want to use the past
records I inherited and that is over 31,00 records. Thanks again for
helping out.

.On 5 Sep 2006 17:22:56 -0700, pi********@hotmail.com wrote:
>
daD wrote:
>OK, I think I am on the right track. All the forms are planned to be
based on queries off the 'current" table, except the 'past guests"
form, which is based off a query of the "archive" table, so I can see
who has stayed with us in the past.

i also have a need to know how many people are in the campground each
day. I would like the databse to run a query every day at maybe 8:00
(it should be the same time every day and should be automated) in the
morning and count the number of camping spaces that were occupied and
then store that number somewhere for later use.

On the right track? if you're thinking of putting all this calculated
junk in a table, I'd beg to differ. If you base your forms off queries
and your tables are properly indexed, and you only pull the data you
need from each table, then who cares how many records are in your
tables? Why not just query the live data? The query is a little
weird, but once you have it, you're there. I think storing all this
junk is a waste of space and time, unless you really need it for
querying later and you have so many records that querying the whole
dataset is unwieldy.
Sep 6 '06 #8
daD <JA********@COX.NETwrote in
news:jg********************************@4ax.com:
OK, OK. Maybe not on the right track? I just need to know how
many camping sites were occupied on a given day and I thought
I should check that number at the same time every day to
establish a standard. This helps me establiush a trend of high
occupancy times of the year and low occupancy times of the
year. Maybe I can offer incentives during the slow months to
lure customers in. How else would I be able to get this info?
You said somnething about indexes? I want to do it the
easiest way possible obviously, but I really want to use the
past records I inherited and that is over 31,00 records.
Thanks again for helping out.

.On 5 Sep 2006 17:22:56 -0700, pi********@hotmail.com wrote:
>>
daD wrote:
>>OK, I think I am on the right track. All the forms are
planned to be based on queries off the 'current" table,
except the 'past guests" form, which is based off a query of
the "archive" table, so I can see who has stayed with us in
the past.

i also have a need to know how many people are in the
campground each day. I would like the databse to run a query
every day at maybe 8:00 (it should be the same time every
day and should be automated) in the morning and count the
number of camping spaces that were occupied and then store
that number somewhere for later use.

On the right track? if you're thinking of putting all this
calculated junk in a table, I'd beg to differ. If you base
your forms off queries and your tables are properly indexed,
and you only pull the data you need from each table, then who
cares how many records are in your tables? Why not just query
the live data? The query is a little weird, but once you have
it, you're there. I think storing all this junk is a waste of
space and time, unless you really need it for querying later
and you have so many records that querying the whole dataset
is unwieldy.
First of all, you should NOT have two tables, current and past
guests. You have one table "guests" and a field that indicates
the "past status", the date and time the guest left. It would
also help to store the date and time the guest arrived, and the
location number...

Then it becomes very easy to query the data for any particular
date and time for the info you want...
SELECT count(location) as Occupancy from Gusest where [enter a
date and time for count BETWEEN dtArrival and dtDeparture.

No need for automation, storing results, etc.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 6 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Caroline | last post by:
I need to update a table by copying a column from another table (having the same structure, but on another database), from the record having the same primary key. 1 - What is the correct...
2
by: Sebastian | last post by:
The following query needs about 2 minutes to complete (finding dupes) on a table of about 10000 addresses. Does anyone have an idea on how to speed this up ? Thanks in advance !!! Sebastian
3
by: radioman | last post by:
Hi all, I would appreciate some help please. I just need pointing in the right direction as I am at a loss. Basically I have a form (frmAddMaster) which displays two subforms "Master Stock...
5
by: Lyn | last post by:
I am trying to copy selected fields from one table to another, by reading the source table record into a recordset (ADO) and then copying the relevant fields to an SQL statement "INSERT INTO...". ...
48
by: phillip.s.powell | last post by:
MySQL 3.23.58 - 4.0.17 (yep, several database server instances, don't ask) I have database Spring with table Students I have database Summer with table Students I am tasked to produce a...
0
by: berwiki | last post by:
I am trying to copy a table to another SQL 2000 Database, but I continually get errors. When I right-click, choose All-Tasks, Export-Data and go through the DTS settings, I get an 'Unspecified...
5
by: ozzii | last post by:
Hi I am using the following code to copy data from one database table into another database table: SELECT * INTO Products From exportdb.mdb.exporttable However the query simply deletes...
1
by: corsibu | last post by:
hello , i just wanted to ask if there's anyone who could help me do the following thing : i have an empty temporary table, this table will have a row filled with data grabbed by a querry at this...
5
by: mark_aok | last post by:
Hi all, I have a situation where I have a split database. At the back end, I need to - create a new table (I will call it newTable) with the exact fields, and relationships as another table...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.