Queries :: Append Query / Adds Records - Despite Key Violation?

Dec 3, 2013

- I have a module which runs queries on linked sales spreadsheets, to merge them in to one Access table.
- To prevent duplication of sales, the primary key merges the sales record and item number fields.

Today, it's found 103 key duplication errors, which is fine. But it's still adding data to the table. The data seems to be fields which aren't even mentioned in the query. It only does this when the query is ran from VBA.

Code:
MergeEbay = "INSERT INTO tblSales ( SalesRecord, SKU, PostCode, Shipping, Quantity, SalePrice, SalesRecordSKU, DateAdded )" & _
"SELECT exEbaySales.[Sales record number], IIf(exEbaySales.[Custom label] Is Null,'0',exEbaySales.[Custom label]), exEbaySales.[Buyer postcode], " & _

[code]...

View Replies


ADVERTISEMENT

Queries :: Append - No Records Are Being Imported / Validation Rules Violation

Jan 15, 2014

No records are being imported. I am getting a validation rule violation but I don't have any rules. The forename and surname are straightforward text boxes and the ID is an autonumber.

Code:

INSERT INTO table_candidate ( Cand_ID, Cand_forename, Cand_surname )
SELECT candidates.Cand_ID, candidates.Cand_forename, candidates.Cand_surname
FROM candidates;

1. Is your append query trying to assign values to the primary key field? Could that be the source of the duplicate?

Yes but there are no duplicates

2. Do you have any other fields that are "Indexed: No Duplicates"? Any compound indexes?

No

3. Is the query assigning values to a field that is a foreign key to another table? Is it possible that these values do not match the values in that other table?

No. All child tables are empty.

4. Is there a validation rule on the table itself?

What this means.

5. Does the query attempt to assign a string with no characters in it (as opposed to a Null value) to a text field that has its Allow Zero Length property set to No?

Both fields are text and all records contain information

Required = No
Zero length = Yes

6. Is there a Default Value in one of the fields that is NOT being assigned by the query? For example, a foreign key with zero as the Default Value?

No

7. Is there data that is outside the range a field can accept, e.g. an integer larger than 32767, or a Null to a Yes/No field?

The length of the text in each record is not greater than the set limit

8. Is one of the query fields arriving in a format that Access is not understanding, e.g. for a date, or for a currency?

No

View 8 Replies View Related

Queries :: Insert Into Query Will Only Work On Some Records - Key Violation Error

Oct 23, 2014

I am building an access database for my college project and I essentially have a quotation form that when I click a button 'Convert to Invoice' it creates a new record in the invoice table and then creates new records in the invoice details table which match the quotation details table. This is working as it should but for only the first 2 customers in my customer table?

On the quote form I have a combo box which is linked to the customer table and updates the quote table based on the selection. If I select customer 1 or 2 and click 'convert to invoice' it works and opens an invoice form based on the inserted data however if I select any other customer it returns an error that the record wasn't added to the table due to key violations?

As far as I can tell I am not trying to update the primary keys in the Invoice Table or the Invoice Details Tables.

View 1 Replies View Related

Append Query Key Violation

Oct 2, 2007

Hi,

I am new user of access and have encounted a key violation from an append query. I'm trying to update a master mail-out list and am having a key violation that doesn't add some of my records.

Here is the SQL vew:

Also, I've checked the properties for both tables and they match, also I have "Allow zero length" set to yes.

I'd appreciate any help, thank you in advance.

View 1 Replies View Related

Append Query Key Violation (as Used In Create Similar Record)

Oct 18, 2007

I have a database of Assessments, each record having multiple subforms.

I am working on a button, which creates a "similar" (same) assessment, copying over all the subform records/selections.

So, after I actually insert a new assessment, pasting all the values from the original Assessment:

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend

I need to copy over subform contents, for which I use an Append Query (actually, I use its SQL in VBA code to pass it the right parameters).

Now, naturally, I ran into Key Violations, because taking 50 sub-records from the original they would have their own AutoNumber Keys (ID's) and I can't append them into the same table.

My question: how do I copy over the same records (appending FROM and TO the same table) but cause the table to insert AutoNumbers for the records being appended?

Thanks!

View 1 Replies View Related

Trying To Append Rows With VBA - Get Key Violation

Mar 9, 2008

Hey all. I'm trying to append rows to my database with some VBA code.

The code looks like this:
vInsertLoanSQL = "INSERT INTO Loan(BookID, MemberID, StaffID, BorrowingDate, ReturnDate) VALUES (" & vBook & "," & vMember & "," & vStaff & ", #" & Format(Date, "dd/mm/yyyy") & "# , #" & Format(vDueDate, "dd/mm/yyyy") & "#)"

DoCmd.RunSQL(vInsertLoanSQL)


The variables are all filled out.

The table that it's being inserted into, Loan, has an Autonumber primary key (not included in the INSERT script) and a number of other fields that have no zero-length restrictions, no "Required" fields set to Yes and no Indexes. The table in question is also completely empty, there are no rows (they have all been deleted) - so I have no idea why I'm getting that "Microsoft can't append all the rows in the append query" error. It says its a key violation but I really can't see how its possible.

Anyone out there know whats going on?

View 5 Replies View Related

Yet Another Append Key Violation Error....

Mar 30, 2008

Wow, this thing is annoying me. I give up! I've attached the database for anyone here to have a look at. I promise there's no nasty code on it, although you should be able to see my code and hopefully pick the problem if you disable macros anyway.

I use VBA to prompt users to enter their staff number, the member's number and the book ID. The same VBA checks to make sure that it's a valid number that they're entering, that's it's actually present in the table it's being referenced from. (Command0 button. Command1 is to return an item)

It then takes these values, the current date and another date variable and inserts into the LOAN table. The loan table has enforced referential relationships with the book, member and staff tables.

The insert code is:
vInsertLoanSQL = "INSERT INTO Loan(BookID, MemberID, StaffID, BorrowingDate, ReturnDate) VALUES (" & vBook & ", " & vMember & ", " & vStaff & ", #" & Format(Date, "Short Date") & "#, #" & Format(vDueDate, "dd/mm/yyyy") & "#)"

All the fields in Loan (except for the autonumber PK) are not required, and have no validation formulas, zero-length is permitted where applicable.

I KNOW that the numbers being inserted are in the related tables! They're the same data type - long integers, and the related tables' primary keys are not autonumbers.

So why am I still getting a key constraint violation??

Can someone please help me??

Correction: I'm trying to attach the database, but it's too big, even zipped. Why isn't RAR accepted? Anyway, the file is hosted here: http://jellopy.com/files/newdb.zip

View 11 Replies View Related

General :: Key Value Violation With Macro Append From Spreadsheet

Mar 10, 2015

I am having problems with an append from a spreadsheet into a pre-populated table. I am using a macro to do this.

The table is in the middle of a hierarchy of tables. For example:

table 1 - Audit - key: AuditNumber & AuditName
table 2 - Process - key: AuditNumber & AuditName & ProcessRef
table 3 - Risk - key: AuditNumber & AuditName & ProcessRef & RiskRef
table 4 - Controls - key: AuditNumber & AuditName & ProcessRef & RiskRef & ControlRef
table 5 - Control tests - key: AuditNumber & AuditName & ProcessRef & RiskRef & ControlRef & TestRef

The front end of the database has a form for each table. Once you create an Audit in table 1 you can create multiple Processes underneath this one audit. Underneath a process you can create multiple Risks...... hence a hierarchy.

I am trying to append data to table 4 - controls. I have copied the format exactly into excel. I have also prepopulated the Audit, Process and Risk data in the required tables.

The reason I want this functionality is to enable team members to populate control information (oftentimes up to 25) in excel and then upload them easily into the database.

The macro I have created will work when created a new table. but when I point it at the existing table 4 - Controls I get the Key value violation error.

View 5 Replies View Related

Queries :: Append Query - Only New Records

Aug 15, 2013

How can I modify the below code so that it only adds new records to AttributesTBL from ProductInformation-Consumer?

INSERT INTO AttributesTBL ( Material )
SELECT [ProductInformation-Consumer].Material
FROM AttributesTBL INNER JOIN [ProductInformation-Consumer] ON AttributesTBL.Material = [ProductInformation-Consumer].Material;

View 2 Replies View Related

Queries :: Make Table Query That Adds A Primary Key

Aug 8, 2013

I have a make table query that gets its info from another table that is updated weekly. I would like that when we run the Query Type (Make Table), we would like to add a primary key to a field that exists already starting at 1 every time the query is run.

View 3 Replies View Related

Queries :: Append And Delete Query - Single Records

Mar 27, 2013

I am creating a database where the records of individual students are to be moved to different table depending on where they are in the graduation process. In order to do this, the secretary will enter the student in the "90 Hr Request" table (think of it as the first step), and move them down the line of tables (4 in total) until the final "Completed" table. Each table in the progression has more and more fields. However, a student (with their ID number as the primary key) can only be in one table at a time.

I understand this does not sound like a traditional database, as the data is not normalized. However, this is being used more as a filing system than anything else. Their data is primarily paper based (for legality reasons), but wishes to keep it organized in a database so they can run queries and print reports.

Currently, I am creating a macro that will run specific queries (in an order). I have made an append query that will move the records over, then I used a update (to null) and delete query combo to delete the old individual record. I made the delete + update query work by using a selected criteria.

How to make the append query move only one student's record at a time.

View 2 Replies View Related

Queries :: Append Query - Unique Records To Create Relationship

Mar 22, 2015

I have created a linked Excel table in Access 2010 called 'tblExcelLinked' and I have a form called 'ASB Log Form' for the purposes of presenting the data in a more readable manner that is easier to view, plus link other fields of data that are not directly related to the 'tblExcelLinked'.

Because there is no unique ID in the 'tblExcelLinked' to create a relationship, I have created a table called 'tblASB', which allows me to add other table data linked from same d/b.

I now want to update the 'tblASB' with data from the 'tblExcelLinked', but only append new records from 'tblExcelLinked', but my inadequate append query is duplicating the records each time I run it, rather than just adding the new ones.

Once sorted my next challenge is a macro so that this runs automatically rather than being manually triggered.

View 3 Replies View Related

MS Access Can't Append All The Records In The Append Query

Feb 18, 2007

hi Guys,
I have been looking at different post and checking Microsoft help files as well, but still can't seem to fix this problem.

I am having 2 tables. The first table is connected to a form for viewing and entering data, and in the second table i am just copying 3-4 fields from the first table.

I am trying to use the insert statement to insert records in the second table, and everytime i click on the "Add" button to add the records i get the following error "MS access can't append all the records in the append query ... blah blah blah"

However if i close the form and reopen it, and goto the record (as it is saved in the first database) and now click on the add button to add the fields to the second table/database, it works.

What am i doing wrong???

Any inputs will be greatly appreciated.

View 3 Replies View Related

Button That Adds As Many Records As You Want

Mar 29, 2006

I want to create a button that adds as many records to a table as you want. So I would have
- a text field where the user would input the number of records
- the code of the button having a for loop or while statement to add that many records as the user typed in

This is my code of a button that adds one record at a time. My VB is not good so could someone tell me how to put in a for loop or while statement that would do the trick? Thanks.

Private Sub addbutton_Click()

If IsNull(Combo0) Then
MsgBox "Please select an Oil to add data (Top left corner)"
Else
Me![Property Subform].Form.AllowAdditions = True
Forms![Values Form]![Property Subform].SetFocus

DoCmd.GoToRecord , , acNewRec
Me![Property Subform].Form![TV_O_ID] = Combo88
Me![Property Subform].Form![T_TT_ID] = Combo86
'Weathering Info
Me![Property Subform].Form![WEATHERTYPE] = Text106
Me![Property Subform].Form![WEATHERUNIT] = Combo104
Me![Property Subform].Form![WEATHER%Num] = Combo102
Me![Property Subform].Form![WEATHER%Text] = Combo100
'Parameter Info
Me![Property Subform].Form![PARAMTYPE] = Combo114
Me![Property Subform].Form![PARAMUNIT] = Combo120
Me![Property Subform].Form![PARAMVALNum] = Combo112
Me![Property Subform].Form![PARAMVALText] = Combo110
Me![Property Subform].Form.AllowAdditions = False

End If

Me![Property Subform].Requery

End Sub

View 10 Replies View Related

Single Form Adds Several Records?

Feb 9, 2008

Hi all,

I already have a form where you specific the date and the store I've purchased something at. I want to be able to add several products I've purchased to a table and define their price, using the same form, so I don't have to input the date and store type for each purchased product.

So, when the form updates the table, it will create a new record for each product, using the product description and price - defined for each product - and using the date and store - defined once - as elements of the record. Is there a way of doing this?

I'm quite familiar with creating tables, forms and queries with the design wizard - not so familiar with using scripts, but I've had a small amount of experience with manipulating databases using MySQL, so I'm willing to learn anything that may be necessary to achieve what I need.

Bugme

View 7 Replies View Related

Queries :: SQL UPDATE That Adds But Doesn't Replace?

Aug 27, 2013

Right now, I'm working with an SQL code of

Code:
"UPDATE Individuals SET [ShareholderOf] = " & Me.CompanyNo & " WHERE [Name] = '" & PerName & "';"

However, doing so will obviously change the "Shareholder of" field into what the user inputs (Me.CompanyNo). What should I use if I want it to ADD the user input rather than REPLACING the old [shareholderof] value?

View 6 Replies View Related

Queries :: Append Records From Main To Secondary Table

May 14, 2014

I built an Append Query to take records of 'Leavers' from my Primary Table and add them to a Secondary Table named 'Leavers. This worked perfectly, but on reflection I determined that I needed to append a further column 'Notes' which exists in the Main Table but not in the Secondary Table.I amended the SQL statement as follows, but the query now fails stating that it doesn't recognize the field 'Notes'.

INSERT INTO Leavers ( [Member ID], Surname, [First Name], [Address 1], [Address 2], Town, PostCode, Phone, [E-Mail], Notes )
SELECT [Mail List].[Member ID], [Mail List].Surname, [Mail List].[First Name], [Mail List].[Address 1], [Mail List].[Address 2], [Mail List].Town, [Mail List].PostCode, [Mail List].Phone, [Mail List].[E-Mail], [Mail List].Notes
FROM [Mail List]
WHERE ((([Mail List].Leaving)=True));

Does this mean that one would need to recreate a new Secondary Table to incorporate the additional field? I have attempted to edit the secondary table by merely adding the 'Notes' field but that doesn't seem to be possible.

View 3 Replies View Related

Queries :: Cannot Append All The Records - Type Conversion Failure

Dec 23, 2013

I keep getting the above error in access 2010 and cannot see where the error is. I have checked that datatypes are the same. It keeps referring to type conversion failure and didn't add (1) record due to a key violation.

Code:
INSERT INTO Requests ( [Request no], [Date-time received], Customer, Dept, Type, [Service level], [Received by], [Date-time due], Quantity, [Cust requestor], Status )
VALUES (9896, NOW(), 'DEMO', 'Demo Ltd', 'I', 'S', 'LT', NOW(), 1, 'LT', 'O');

View 5 Replies View Related

Queries :: Append Distinct Records Only If Field Have Changed

Jun 5, 2013

Using a database 2010. I have a monthly import from a spreadsheet to one of my tables. Sometimes it has the same previous data from prior month or months that has not changed. I don't want to keep appending this data to my table if none of the fields have changed.

Is there a way to append data to table only if fields have changed in an append query? Ex. (Name, Address, PhoneNum, Rate) If all fields are the same; don't append. If one or more fields are changed; append.

View 14 Replies View Related

Primary Key Violation In Update Query

Apr 21, 2006

Hey, I am getting a primary key violation when I try to run an update query.

My primary key is a combination of two fields, ScheduleID and SchedulePage. That way for each schedule I can only have one Page 1, one Page 2, etc.


When I want to insert a page (say a new Page 2), I need to update the table so that Page 2 becomes Page 3, Page 3 becomes Page 4, and so on.

The problem is, since it starts at the bottom, when I tell it to increase the page number by one, it's conflicting with the primary key of the next record.

Any ideas? BTW, if the solution has to do with sorting, I need to make sure it's something that always defaults back to the correct sort, since users may be able to change the sort and accidentally save it. Plus, I'll need to do the same thing in reverse (delete a page).

DoCmd.RunSQL "UPDATE Pages " & _
"SET Pages.SchedulePage = [SchedulePage]+1 " & _
"WHERE (((Pages.ScheduleID)= " & varScheduleID & ") AND ((Pages.SchedulePage)>" & varSchedulePage & "));"

View 3 Replies View Related

Append Records To Query

Apr 17, 2008

I need help with ACCESS query. I am not at all good with access queries and am unable to figure this out even though it may have an easy solution.

There is an existing query designed by our company in a database. This query links different fields from 4 more queries and finally generates 16 columns as shown below. (I have also attached excel file with the same example as the text below is not aligned)

Name(1)ReportDate(2)TB(3)MV(4)NC(5)AI(6)SN(7)LN(8)SID(9)Country(10)PVS(11)BMV(12) Fund Code(13)MV by Fund code(14)Total TNAD(15)CUR(16)
ABC3/31/2008USDACDUDna0$150.00abcd $731.00 $745.00 CAD
ABC3/31/2008USDBCDUDna0$256.00abcd $731.00 $745.00 CAD
ABC3/31/2008USDCCDUDna0$325.00abcd $731.00 $745.00 CAD
XYZ3/31/2008CADACDUDna0$112.00wxyz $387.00 $420.00 CAD
XYZ3/31/2008CADBCDUDna0$275.00wxyz $387.00 $420.00 CAD
PQR3/31/2008EURCCDUDna0$60.00pqrs $166.00 $200.00 CAD
PQR3/31/2008EURACDUDna0$72.00pqrs $166.00 $200.00 CAD
PQR3/31/2008EURBCDUDna0$34.00pqrs $166.00 $200.00 CAD


In this example I am just showing 8 records, but in reality there usually about 4000 records and the number changes every day.


Now I am asked to design a query based on the query that gives the above results.

The 14th column (heading –MV by Fund code) actually sums up the market values in column 12 (BMV) that has same fund code in column 15. For example for fund code “abcd” the BMV are $150, $256 and $325 which sum upto $731 and hence this number shows up in column 14 against each record with “abcd” fund code.

Now there is a difference of $14 between column 15 (heading-Total TNAD) and column 14 (heading- MV by Fund Code) for fund code “abcd”. I am asked to design a query that will add records on the results generated above by the existing query.

The new record added should show the difference of $14 in column 12 and text “OTH” column 8 and column 9 and should show the fund code “abcd” . The values in remaining columns should be the same as the fund code “abcd”.

The above logic would then apply to funds “wxyz”, “pqrs” and so on

In this example the following three records should be added below the above 8 records with these details

ABC3/31/2008USDAOTHOTHna0$14.00abcd $731.00 $745.00 CAD
XYZ3/31/2008CADAOTHOTHna0$33.00wxyz $387.00 $420.00 CAD
PQR3/31/2008EURBOTHOTHna0$34.00pqrs $166.00 $200.00 CAD


I guess this would require coding in SQL. But I am unable to do so.

Any help is highly appreciated

Thanks,

Peace

View 7 Replies View Related

Append Query Overriding Records?

Jan 9, 2007

Access 2000

Tbl_TEMP
Tbl_MAIN
Frm_ENTRY

My user opens frm_ENTRY. Which is pulling data from tbl_TEMP. They clean up a few fields on the form. Then click a button which executes an append query which appends the data to tbl_MAIN.

My problem is sometimes when it appends the data it is overriding older data. It is not creating a new line each time. It simply overrides an existing record. Does this make any sense at all?

There are many other forms, queries, tables and macros in this DB. If that matters at all. I think it has something to do with a bound form that is connected to a drop down from a query, but I have no way of trouble shooting this? Where do I start?

View 3 Replies View Related

Append Query Single Records

Apr 27, 2006

Thanks for taking the time to look at my problem first of all. I have a form that shows records but I want a button next to each record that will append that one single record to another table that is built exactly the same, which is for historic records. Not the brightest on Access and I can only manage to append all records.

As an example, I have an employee record that have a task, when the task is complete I want to append the record to a historic table that I can look up later on. However, just that one employee and not all that are in the current table.

View 6 Replies View Related

How To Copy Linked Records (append Query?)

Jan 16, 2008

I have attached an image of the 2 tables concerning my question.

The main "transaction" table is the tblAssessments and a linked table tblRisks drives a subform - showing multiple Risks per assessment.

The field "OccupantID" identifies the facility where Assessments are done (there are other tables, of course).

I am using an OccupantID "00000" to store templates - pre-filled assessments with most common options selected.

I am trying to develop code and/or query or SQL that would do this:

copy all templates (records from OccupantID 00000) and corresponding sub-records from tblRisks into the same tables, but under a different (selected by user) OccupantID.

I have no problem just using an Append Query (actually a SQL statement in VBA with variable parameters), but that only lets me copy into 1 table - so I can copy just the tblAssessments records.

but how do I then copy the tblRisks related records and make sure I attach them to the correct AssessmentID?

View 5 Replies View Related

Append Query Also Updating Earlier Records

Nov 7, 2006

Can anyone help me with this - I have an append query to a statement table for invoices with a macro set. When the query is run the data is added to the statement query.

what is happening is that it is adding the data ok on a seaparate line but is also updating any previous invoices for the same client to the new invoice number obviously not what I want.

many thanks

Regards

Humph

View 1 Replies View Related

Using An APPEND Query To Move Records From One Table To Another...

Mar 10, 2008

I have an order system whereby there is a "basket" table and an order detail table.

I want to use an append query to move all the records from the basket table to the order detail table.

However, I also need to mark each record that gets appended to the order detail table with an "Order Id" that has already been saved in an Order table.

I.e. I save the main details of an order into the order table then copy records from the basket table into the order detail table along with an order ID that comes from a form.

The order ID is an autonumber.


Thank you all so much in advance =]

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved