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 Replies


ADVERTISEMENT

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

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

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

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 3 Replies View Related

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

Modules & VBA :: Transfer Spreadsheet And Append Additional Fields

Jun 1, 2015

I am trying to use transferspreadsheet to import access worksheet and then I want to append additional fields. I am able to import the excel sheet into access, but need appending the other fields.

Code:

Dim fd2 As FileDialog
Dim xlapp As New Excel.Application
Dim xlsht As Excel.Worksheet
Dim xlWrkBk As Excel.Workbook
Dim db As DAO.Database
Dim tb2 As TableDef
Dim fdx, fld As DAO.Field

[code]...

View 4 Replies View Related

Append And Delete Query Parameters Not Working In Macro

Jan 16, 2013

I've been creating a simple macro which will append data and then delete data from a table.The criteria for the queries is found in a form, and this is used as a paramter.However, when i run this all as a macro...the append and delete queries somehow can't read the criteria in the form. Rather...i have to type in the criteria again...and then it works.I have attached a copy of my DB.

1. Go to frmArchiveStock
2. Select a stock from the combo box (this the criteria for the append and delete queries)
3. Click the button to run macro mcrStockArchive.

How can i get the queries to pick up the value entered in the form to act as a criteria when they run?

View 1 Replies View Related

Suppressing Dialog On Multiple Append And Delete Queries In A Macro

Aug 19, 2004

I have a macro setup that deletes all the records in 2 different tables, then using about 8 queries, appends several records to the two tables where data was deleted. When these macros run, several Yes/No/Cancel dialog boxes come up for each query, first asking you if you are sure you want to do this, that it is going to change data in my table, and then second telling me how many records it's going to append or delete.

Is there a way to make it automatically run Yes to all of these dialog boxes? That would really help out a whole lot. Of instead of that, but maybe some sort of VB code that could do all the deleting and appending without the need of the Macros, and that doesn't require user intervention. I have my Macro's setup on the "On Click" event in a form, so using VB would be no problem at all.

Any Suggestions?

View 10 Replies View Related

Queries :: Press A Button And Run A Macro / Append Query To Add A Single Summary Record To Another Table

Aug 2, 2013

I have a query run that gives me a list of records that I view on a continuos form. What I want is to press a button and run a macro/Append Query to add a Single Summary record to another table.

For example my query spits out this data

Part # Quantity Serial Number
GO2 1 123
GO2 2 456
GO2 2 789

What I'm looking to get is

Part Number Total Quantity Serial Number 1 Serial Number 2 ..
GO2 5 123 456

I'm stuck on a couple of things.

1. Getting a new single row to append.
2. Getting Serial Numbers from several records to save on to a single record.

View 4 Replies View Related

General :: Spreadsheet For Attendance Hours / Employee

Nov 3, 2013

I have:

- tbl_company (containing company info)
- tbl_employee (containing employees info)
- tbl_cim (containing working contracts info, related with both tbl_company and tbl_empployee)

In the tbl_cim i have starting date of the contract, working time per day (in hors, according to the contract), ending date of the contract, etc.

I need:
- once a month i have to generate a "excel-like" sheet containing employees (rows) on a selected company, days of the month (1-31) i choose (columns) and hors worked on each day (according to the working_time from tbl_cim). The working hours i have to be able to modify.
- the days before start date of the contract have to be empty; the days after end date, also.
- the saturdays and sundays have to be marked ina different color (cell background).

I ask:
- what tables i have to create additionally?
- how can i create a form for this infos?
- is there a way to do this with less vba as possible?

In my country, Romania, this type of "spreadsheet" is called a "pontaj" and companies have to do it every month. I would like to step from Excel to Access with it.

View 1 Replies View Related

General :: Import Spreadsheet With Multiple Tabs Into Access

Aug 20, 2013

Need to get these into Access from an excel spreadsheet (located on sharepoint). I'm using the spreadsheet fields to create the table fields in Access.

View 4 Replies View Related

General :: Complex Spreadsheet With Unique User View?

Dec 19, 2014

The spreadsheet I've attached contains a ton of calculated cells and linked data. The people who created and utilize it aren't necessarily interested in changing the way they use it or populate it each quarter. That being said, my task is to somehow create a way that it can be sent to/seen by each person differently. First I'll point out that the 3 columns that are blank normally contain names, I deleted them for obvious reasons. The first of those columns, B, contains unique names for each agent in the firm, these people need to ONLY see their own data. The second column of names are basically managers, they need to see the records for each agent that falls under them. The 3rd column of names is irrelevant for these purposes.

Now if all this data were in access, and everyone had access to it I could easily just make records visible or invisible based on user name and I wouldn't be here right now. But they can't and that's not an option. I honestly don't know if this should be done solely in Excel, in Access or a bit of both. Currently this spreadsheet gets emailed to each manager and they have to review the data with each agent.

The first tab, worksheet, is basically instructions. It would be nice if those were images on the page and then all of the data were below that so that the agents could see them together and understand it better. As I'm sure you'll see it's a pretty complicated system so they have a hard time understanding it.

Note: There are actually about 3,000 records, I've deleted most of them for size purposes.

View 4 Replies View Related

General :: Import Excel Spreadsheet From External Source

Aug 19, 2013

I'm in the process of importing an excel spread sheet from an external source (SharePoint).

I have the link for the file and have edited it from the Https:// to projectspace. intranet.sharpoint etc etc.

The problem I'm having is before importing the data into a new table in my current db I get an error

"The File "projectspace.intranetetc etc" does not exist.

I am using IE8 and the version of Access is 2007.

View 3 Replies View Related

General :: Normalize Data From Spreadsheet Prior To Load To Access?

Dec 17, 2013

I have a large spreadsheet I need as the basis for an Access database.

The spreadsheet contains... Company Number, Name, Address, etc...

The Company number is consistant and always the same..

However the Name and address is different... eg LTD v Limited, ABC House v 34 High Street etc....

how I can prepare the data and get into access?

View 3 Replies View Related

General :: Update Preformatted Excel Spreadsheet With Access 2010 Query?

Jun 10, 2013

I have an Access crosstab query that I have exported to an Excel Spreadsheet. I have the spreadsheet formatted using conditional formatting and I'd rather not have to reset it every morning. It's a single spreadsheet (the columns/rows will not deviate greatly day to day) and should be very simple, but I'm not getting it for some reason.

So if I have "Test.accdb" and it contains "qryX" as my crosstab and "Sheet1.xls" is my formatted Excel spreadsheet, how do I code for the latest "QryX" to go in and replace the old "QryX" data in "Sheet1.xls" ?

View 2 Replies View Related

General :: Add Table Macro?

May 20, 2014

im working on a project , and i need to add a sale and delivery option like a table connected to a member customer with product list and price and in the end put all together in a report. Like a bill.

View 1 Replies View Related

General :: Task Scheduler To Run Macro?

Mar 19, 2014

Just got a new Windows 7 computer and installed Office 2013. I have a report that saves itself as a pdf in a temp folder and then attaches the pdf to an email and sends it out. I use a macro to run the report and everything works fine from there. I have a VBS file that runs the macro and clicking the vbs file makes everything work fine. the code is below.

When I tried to run it though the task scheduler it show as completing fine, but it doesn't. So I added a reference the vbs in a batch file (below) and output the logs to a temp file. After I ran the batch and opened the log I seen the message

Wed 03/19/2014 14:11:17.74 Username
C:Users*****DesktopAuto Reportsaragingrecent.vbs(1, 1) Microsoft VBScript runtime error: Permission denied: 'CreateObject'
Wed 03/19/2014 14:11:17.77

I turned UAC all the way down. turn off the virus scanner, and have local and domain admin access. I'm at bit a lose here. I had this working before but can't seem to remember how I did it. This is just one example I have several other reports that were schedule to run overnight, but they basically all use the same code and processes.

Code:
'launch macro
set accessApp = CreateObject("Access.Application")
accessApp.OpenCurrentDatabase "C:Users******DesktopAuto ReportsAgedTrialBalance.mdb"
accessApp.DoCmd.RunMacro "MCRecent"

[Code] ....

View 2 Replies View Related

General :: Get Value From Combobox And Make It Run A Macro?

Sep 7, 2012

How can i get vba to do this.

When i click a button on the main form the vba code will execute and get the value from the combobox ie TE4700 and locate the macro with the same name ie TE4700 with reports in then it will run the macro and print off the reports.

View 1 Replies View Related

General :: Run Macro On Word Doc Closing

Sep 25, 2012

is it possible to run a macro in access 2010 on close event of a word doc. i want to run an update query when i have sent some email. i want to first make sure i send the emails and the when i have finished close the word doc and then open query [QueryName].

View 2 Replies View Related

General :: Macro To Prompt Depending On Checkbox

Nov 12, 2013

I need to display a message on a form after a record update has been done depending on whether a table field is ticked or not. If it is ticked I want one message if it is not ticked I want a different message, but here is the scenario.

I have a form and one of the options I have is to call up an address from a record in a table. I want it to display a message to advise whether there is a special requirement for delivery to the address, so in the table I have a checkbox field. If its checked, once the address has been pulled up I want it top advise 'special requirement' or 'no special requirement'.

I need to do this in a macro form, or expression form if possible as I already have an after update macro when that drop down is selected.

So on the dropdown list I have the following on the afterupdate function:

SearchForRecord
Object Type :
Object Name :
Record: First
Where Co0ndition - - "[ID] = "& Str(Nz([Screen].[ActiveControl],0))

That brings up the address from a record in my table onto this form, so what I want is if that record has got a tick the checkboxfield it prompts with a message and ok button.

View 3 Replies View Related

General :: Use VBA To Click A Button That Fires A Macro?

Sep 4, 2012

enable me to run some code before a button is clicked I want to be able to click a button via VBA code.Basically I used the auto button wizard to make an add record button.To ensure a shed loads of if checks and queries on the entered form data run I wanted to make this button invisible, then make a new button running code not embedded macros to run my checking module then click.

View 9 Replies View Related

General :: Macro To Manipulate Unstructured Data

May 5, 2015

I have some tables need to be imported to Access, which is not well structured. For example:

report
4/05/2014
from SQL server
Name ID Add.....
aaa 111
bbb 222

To be more specific,I have 4 csv files, that need to be imported into Access.

1. I'm building 4 linked tables so users can update the table as needed. Then run queries based on these tables to produce report. But maybe there's a better way? the file name and location might be dymatic, so anything like 'getopenfile' would be easier instead of linked tables?

2. These data need to be clean up first to become a 'database table'. (Delete first 2 rows, delete some columns, remove duplicates etc.) I know how to do them in VBA Excel, but never used Macro in Access before.

View 1 Replies View Related

General :: Create A Macro That Begins After Update

Apr 3, 2013

I have a tabular form that lists all the records (address book). I'm trying to have a combo box filter the records by selecting a contact type (employee, supplier, customer). So far I have the contacts displaying in the combo box.I've tried to create a macro that begins "after update". Its an ApplyFilter macro.

Where Condition = [Contact Type]=[Contact Type Select]

[Contact Type Select] is the combo box.

When I do this, a popup box appears. When I type in the item I want, it works. I want this done automatically.

View 1 Replies View Related

Key Violation Error

Mar 17, 2008

Hello I am new to this forum. I am trying to use the append query on two tables that are identical in data type, from TblA to TblB, but cannot append due to key violations for each row.

Both TblA and TablB have an autonumber primary key, although TblA does not need to have a primary key. Any suggestions as to what I should be looking for first?

Thanks

View 14 Replies View Related







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