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

Violation errors while inserting data from one table into another

Hi,

I am getting errors while inserting records in one table from another.


These are the structures of two tables :

file51tm_new

RecordType Text
RecordNumber Number
WorkCOde Text
Date TExt
Tck_nbr Text
time text
transno text
Start_date Text
End_date TExt
Tk_serial Text
tck_price text
void_code text
mag_encode text
red_date text
red_time text
batch number

file51tm_new_1

RecordType Text
RecordNumber Number
WorkCOde Text
Date date/time
Tck_nbr number
time text
transno number
tck_type number
Start_date date/time
End_date date/time
Tk_serial text
tck_price number
void_code text
mag_encode text
red_date date/time
red_time text
batch number


And this is the query :

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO FILE51TM_New_1 ( RecordNumber, WorkCode, [Date], Tck_Nbr, [Time], TransNo, Tck_Type, Start_Date, End_Date, Tk_Serial, Tck_Price, Void_Code, Mag_EnCode, Record_Type, Batch )
  2. SELECT FILE51TM_New.RecordNumber, FILE51TM_New.WorkCode, IIf([Date]<>"",[DATE],"") AS Expr1, FILE51TM_New.Tck_Nbr, FILE51TM_New.Time, Val([TransNo]) AS Expr4, FILE51TM_New.Tck_Type, IIf([START_DATE]<>"",(Mid([Start_Date],1,2) & "/" & Mid([Start_Date],3,2) & "/" & Mid([Start_Date],5,2)),"") AS Expr2, IIf([END_DATE]<>"",(Mid([End_Date],1,2) & "/" & Mid([End_Date],3,2) & "/" & Mid([End_Date],5,2)),"") AS Expr3, FILE51TM_New.Tk_Serial, FILE51TM_New.Tck_Price, FILE51TM_New.Void_Code, FILE51TM_New.Mag_EnCode, FILE51TM_New.RecordType, FILE51TM_New.Batch
  3. FROM FILE51TM_New
  4. WHERE (((FILE51TM_New.Batch)=DMax("[FILE51TM_New]![Batch]","FILE51TM_NEw")));
I am trying to insert records from file51tm_new into file51tm_new_1 where the batch field is max and in the process, I am converting date fields ( in text format ) into date format. I get the following error :

Microsoft Access can't append all records in th query
Microsoft Access set 8 fields to Null due to a type conversion failure, and it didn't add 0 records to the table due to key violations, 0 records due to lock violations, and 0 records due to validation rule violations.


There is no primary key defined on either of the two tables, and there are no validation rules for any of the fields in both the tables.


Anybody able to help me on this ?

Would appreciate any solutions.

Thanks in advance,
Jun 14 '07 #1
13 3023
MMcCarthy
14,534 Expert Mod 8TB
Your problem is with your dates. You are trying to convert text to date/time

For example,

IIf([Date]<>"",[Date],"") AS Expr1

Should be

IIf([Date]<>"",Format([DATE], "dd/mm/yy",Null) AS Expr1

I've used european date format but you can use whichever format is suitable to your database.

Follow the same rules for the other dates. You cannot use "" for the value if false as this is a string, so I've used Null.
Jun 14 '07 #2
I tried this option, but I still get the same error.....



Your problem is with your dates. You are trying to convert text to date/time

For example,

IIf([Date]<>"",[Date],"") AS Expr1

Should be

IIf([Date]<>"",Format([DATE], "dd/mm/yy",Null) AS Expr1

I've used european date format but you can use whichever format is suitable to your database.

Follow the same rules for the other dates. You cannot use "" for the value if false as this is a string, so I've used Null.
Jun 14 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
I tried this option, but I still get the same error.....
Did you do this for all date fields?
Jun 14 '07 #4
NeoPa
32,556 Expert Mod 16PB
I tried this option, but I still get the same error.....
Check if the field properties for the date fields in the resultant table (where you're inserting the data into) have allowance for Nulls.

PS. Also consider how you WANT these values to be handled.
Jun 14 '07 #5
Well, the other date fields are string fields in format "mmddyyyy". so i have to format them the way i am doing it in the query ( and cannot use the format function on them ).
Jun 14 '07 #6
MMcCarthy
14,534 Expert Mod 8TB
Well, the other date fields are string fields in format "mmddyyyy". so i have to format them the way i am doing it in the query ( and cannot use the format function on them ).
You can't insert a string into a date field. At least change the value if false to Null in each case.
Jun 14 '07 #7
It is very strange...... MS Access is giving that error. But when I click on 'Yes' to ignore the error and run the query, it inserts those records that i want.
Jun 14 '07 #8
NeoPa
32,556 Expert Mod 16PB
Well, the other date fields are string fields in format "mmddyyyy". so i have to format them the way i am doing it in the query ( and cannot use the format function on them ).
Why can't you use Format()? I would.
Jun 14 '07 #9
MMcCarthy
14,534 Expert Mod 8TB
It is very strange...... MS Access is giving that error. But when I click on 'Yes' to ignore the error and run the query, it inserts those records that i want.
It is probably just inserting nulls instead of those empty strings.
Jun 14 '07 #10
if i use format directly on the text fields it gives incorrect date values.
Jun 14 '07 #11
Anyways, thanks for the help.
Jun 14 '07 #12
NeoPa
32,556 Expert Mod 16PB
If I use format directly on the text fields it gives incorrect date values.
That's probably just because you're not using them correctly.
Let's focus on a single field for the moment.
Post here what you start with and what you hope to be inserted into the other table. I'll see if I can find the correct code for translating it. Remember, it is very important to know if Nulls are possible, or empty strings, and also which values are accepted by the destination table.
Choose any of the date fields, but do be clear about what you've selected.
Jun 14 '07 #13
FishVal
2,653 Expert 2GB
Hi,

I am getting errors while inserting records in one table from another.


These are the structures of two tables :

file51tm_new

RecordType Text
RecordNumber Number
WorkCOde Text
Date TExt
Tck_nbr Text
time text
transno text
Start_date Text
End_date TExt
Tk_serial Text
tck_price text
void_code text
mag_encode text
red_date text
red_time text
batch number

file51tm_new_1

RecordType Text
RecordNumber Number
WorkCOde Text
Date date/time
Tck_nbr number
time text
transno number
tck_type number
Start_date date/time
End_date date/time
Tk_serial text
tck_price number
void_code text
mag_encode text
red_date date/time
red_time text
batch number

And this is the query :

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO FILE51TM_New_1 ( RecordNumber, WorkCode, [Date], Tck_Nbr, [Time], TransNo, Tck_Type, Start_Date, End_Date, Tk_Serial, Tck_Price, Void_Code, Mag_EnCode, Record_Type, Batch )
  2. SELECT FILE51TM_New.RecordNumber, FILE51TM_New.WorkCode, IIf([Date]<>"",[DATE],"") AS Expr1, FILE51TM_New.Tck_Nbr, FILE51TM_New.Time, Val([TransNo]) AS Expr4, FILE51TM_New.Tck_Type, IIf([START_DATE]<>"",(Mid([Start_Date],1,2) & "/" & Mid([Start_Date],3,2) & "/" & Mid([Start_Date],5,2)),"") AS Expr2, IIf([END_DATE]<>"",(Mid([End_Date],1,2) & "/" & Mid([End_Date],3,2) & "/" & Mid([End_Date],5,2)),"") AS Expr3, FILE51TM_New.Tk_Serial, FILE51TM_New.Tck_Price, FILE51TM_New.Void_Code, FILE51TM_New.Mag_EnCode, FILE51TM_New.RecordType, FILE51TM_New.Batch
  3. FROM FILE51TM_New
  4. WHERE (((FILE51TM_New.Batch)=DMax("[FILE51TM_New]![Batch]","FILE51TM_NEw")));
I am trying to insert records from file51tm_new into file51tm_new_1 where the batch field is max and in the process, I am converting date fields ( in text format ) into date format. I get the following error :

Microsoft Access can't append all records in th query
Microsoft Access set 8 fields to Null due to a type conversion failure, and it didn't add 0 records to the table due to key violations, 0 records due to lock violations, and 0 records due to validation rule violations.

There is no primary key defined on either of the two tables, and there are no validation rules for any of the fields in both the tables.


Anybody able to help me on this ?

Would appreciate any solutions.

Thanks in advance,
You can use DateValue function
Example of append query for 1 field.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblNew ( dteDate )
  2. SELECT IIf(nz([tblOld]![strDate])="",Null,DateValue([tblOld]![strDate]))) AS dteDate
  3. FROM tblOld;
iif avoids passing empty strings and nulls to DateValue function otherwise resulting in error message You've seen

you can use DateValue function w/o IIf, Access will fill recordfields unable to be evaluated with nulls when you choose Yes on prompt

Good luck.
Jun 15 '07 #14

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

Similar topics

10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
5
by: dotyet | last post by:
I have been given the daunting task of sql query tuning. I am looking for ways to get started with that. I am on DB2 UDB 8.2 (8.1 with Fixpak 8) on Windows. One point which I could think about...
12
by: Steve Jorgensen | last post by:
Hi all, I've migrated an Access database schema to PostgreSQL, and I'm trying to get everything working again. I'm having the following problem... Within an Access transaction, I insert a row...
7
by: Bonnie R | last post by:
Hello! I am writing VBA code in Access 97 to import an Excel 2000 Spreadsheet. I had hoped to do this using ODBC, but that was not to be, for who knows what reason. The problem is that I import...
2
by: Vladimir O¾ura | last post by:
I am building a pocket pc application that requires a datagrid. I am inserting a new row this way: private void mInsert_Click(object sender, System.EventArgs e) { try { DataRow dr =...
5
by: Vayse | last post by:
In my save code, most of items save fine. But sometimes I get a concurrency violation message. "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." It happens on the...
3
by: Bob Alston | last post by:
I have a routine to copy data to new versions of my app via insert into sql statements. Unfortunately, due to evolution of my app, sometimes the new version has more restrictive editing than an...
2
by: John | last post by:
The ASP application inserts transaction records in transaction table with the system time as the primary key. However, it is possible to have primary key violation because the records in...
3
by: fingermark | last post by:
If it's possible, can someone tell me how I could ignore and log SqlBulkCopy duplicate key errors? So, if the bulkCopy.WriteToServer(dt); errors on duplicate key, I want it to log what the row...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.