473,411 Members | 2,272 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,411 software developers and data experts.

How to transfer data from one table to another based on date

34
Greetings (again)...

This should be a simple matter but I cannot seem to find any information on how to do/build this.

Inside a single DB I have two tables... One is titled Employee Submissions and the other is Hours Archive.

What I need is a way to transfer records from the Employee Submissions table to the Hours Archive table based on the date associated with the field. Specifically I need any record older than 2 months to be transfered to the Hours Archive table. I also want the records in the Employee Submissions table to be deleted after the transfer.

Any thoughts?
Sep 30 '10 #1
8 1912
Mariostg
332 100+
This should get you started:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [Destination Table] ( Field1, Field2, recordDate )
  2. SELECT T.Field1, T.Field2, T.recordDate
  3. FROM [Employee Submissions] T
  4. WHERE (((T.recordDate)<=DateAdd("m",-2,Date())));
  5.  
Sep 30 '10 #2
MOCaseA
34
Every time I edit it with the specific information it comes back with an "Expected" error.

Here are the table Names:
Employee Submissions
Hours Archive

These are the fields (they are the same for both tables):
empName
Direct Hours
Indirect Hours
Other Hours
entDate
Other Details
Presence

this is the gist of the code I derived:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. INSERT INTO [Hours Archive] (empName, Direct_Hours, Indirect_Hours, Other_Hours, entDate, Other_Detail, Presence) 
  3. SELECT T.empName, T.Direct_Hours, T.Indirect_Hours, T.Other_Hours, T.entDate, T.Other_Detail, T.Presence
  4. FROM [Employee Submissions] T
  5. WHERE (((T.entDate)<=DateAdd("m",-2,Date())));
  6.  
  7. End Sub
The error is "Expected: end of statement" and highlights [Hours Archive]
Sep 30 '10 #3
Mariostg
332 100+
I am sorry, every time you edit what? And what do you mean my specific information?
Did you adapt the query to your needs?
Sep 30 '10 #4
MOCaseA
34
Sorry... Every time I open the form (Event Procedure) I get the error. Above is the adapted (at least what I derived and adapted) code.

As I have mentioned before, I'm not very good with VB, but there is no one else here familiar with Access to build this DB.
Sep 30 '10 #5
Mariostg
332 100+
Of course, if you want to use this through a form it is not going to work as is. This will work if you paste it in the SQL editor of the query designer. Then you can save it and run it as a query.

If you want to use it in a form action event, go like so:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. dim SQL as String
  3. SQL = "INSERT INTO [Hours Archive] (empName, Direct_Hours" & _
  4.     ", Indirect_Hours, Other_Hours, entDate, Other_Detail, Presence)" & _
  5.     " SELECT T.empName, T.Direct_Hours, T.Indirect_Hours" & _
  6.     ", T.Other_Hours, T.entDate, T.Other_Detail, T.Presence" & _
  7.     " FROM [Employee Submissions] T" & _
  8.     " WHERE (((T.entDate)<=DateAdd('m',-2,Date())));"
  9. DoCmd.RunSQL SQL
  10. End Sub
  11.  
Sep 30 '10 #6
MOCaseA
34
Quick question... Will this string require a SQL server or SQL services to be running? If so, neither of them are running on this system.

When I try to execute this code it gives me the following error:

Run-time error '3134':

Syntax error in INSERT INTO statement.

When I run the debugger it highlights the DoCmd.RunSQL SQL Line (I'm assuming this is because this is the actual command that initiates the code)
Sep 30 '10 #7
Mariostg
332 100+
What about your field names? Are they like Indirect Hours or Indirect_Hours?
If there is a space, you must enclose them in bracket : [Indirect Hours]
Sep 30 '10 #8
MOCaseA
34
Never mind... I just got laid off so no more working on this DB... sorry to be such a bother...
Sep 30 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bryan | last post by:
Hi, I have two tables. I want to update two columns in my first table, and with two values and held in my #temp table but based on a RUN_DATE from my first table. Can anyone point me in...
2
by: Niyazi | last post by:
Hi, I have BIG question and I gues it is the BEST question. I have a problem that I am guessing the best solution is to create some sort ..NET Services. This Service(s) must check every...
8
by: Woody Splawn | last post by:
Lets say I have a winform that is populated with a dataset. The dataset and data table may have several rows in it. Lets say I am looking at the winform and I want to assign a value to a certain...
3
by: Chris S | last post by:
I'm relatively new to VB.NET and have what's probably a very simple question. I'm trying to get one form to access (view and modify) data on another form. For example, the startup object is a...
1
by: Vasilis X | last post by:
Here is the question : I have a data table, UnShorted, which has a data column EventTime (type : date time) and a data column Values (type : single). I want to create a table, Shorted, that...
2
by: rfmatthews | last post by:
I am not familiar with programming languages. I use Access because it is simple to construct queries. PROBLEM: In a database used to calculate employee payslips everything went smoothly on both...
10
by: coffeesin | last post by:
Hi, I have a Table containing these fields: id-no, cold, cold ever, cold date,flu,flu ever and flu date. (The properties of id-no, cold,cold ever,flu,flu ever are set as Numbers.) What i want...
13
by: hexagram | last post by:
hi guys can anybody can teach me how to do this scenario Transfering Data of a form to a new form The Scenario is: I have a Delivery Receipt Form (Hardware) with a fields of the following ...
8
by: ivijayan | last post by:
HI. I have the following query:- How do i create field which updates its contents on the basis of data in another field in same record. especially if I have a Date field, how can I change the...
0
by: Ro | last post by:
I've been given the task of transfering data from an access db to sql server 2000. The previous access db was not structured very well so we reconstructed the tables in sql server 2000 to add...
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: 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:
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
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...

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.