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 : - 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 )
-
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
-
FROM FILE51TM_New
-
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,
13 3023
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.
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.
I tried this option, but I still get the same error.....
Did you do this for all date fields?
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.
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 ).
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.
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.
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.
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.
if i use format directly on the text fields it gives incorrect date values.
Anyways, thanks for the help.
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.
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 : - 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 )
-
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
-
FROM FILE51TM_New
-
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. - INSERT INTO tblNew ( dteDate )
-
SELECT IIf(nz([tblOld]![strDate])="",Null,DateValue([tblOld]![strDate]))) AS dteDate
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |