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 Replies
ADVERTISEMENT
Oct 9, 2006
Hi
I have a main table in my database. For each record in this table there may exist 0, 1 or many records linked to it in a secondary table.
I have created a form for viewing the records in the main table, and now want to link to a second form that displays the records in the secondary table, if indeed any exist for the main record being displayed on form1.
Specifically . .
If I can detect whether secondary records exist for each record in the first, how can I pass a parameter (ie Table1id) to the secondary form so that we can view only the secondary records associated with the main record selected ?
thanks
ajm
View 2 Replies
View Related
May 29, 2014
In my simple database (attached), I need to mass duplicate Tasks and their Notes.
I have three tables: tbTasks (PK: Task_ID), tbNotes (PK: Note_ID), jtbTaskNotes (FKs: Task_ID and Note_ID). jtbTaskNotes is my many-to-many junction table that ties Tasks to Notes.
The main form (fmTasks), bound to tbTasks, has a subform (sbfm_TaskNotes) that displays notes associated with each Task. On themain form,you select which Tasks you want duplicated via a checkbox. The append query (quCopyTasks) will duplicate all tasks that have the checkbox checked. All good there. However, I can't figure out how to also duplicate each task's Notes.
I found Allen Browne's solution [URL] ....., but that only handles duplication of one record at a time, whereas I need to duplicate many records at a time (sometimes 10+ records). How do I go about duplicating multiple Tasks and their associated Notes?
Before you ask "why are you duplicating records?": There are times when tasks need to be re-accomplished and therefore need to have a new record. It's easier to duplicate records than it is to hand-jam everything again.
View 5 Replies
View Related
Apr 11, 2007
Hoping someone can help me with this DELETE query. I have a Main table that's being updated by a Temp table that's an exact copy of the Main table but with a subset of records.
1) Insert records from Temp table NOT found in the Main table - this query I have worked out below - not tested, but the results look correct.
Need Help Here...
2) Delete Records from the Main that are not found in Temp table with an exception...only DELETE records where certain key fields are matching. i.e. If S.CAD_NAME, lngStoreNumber are a match to what's in the Main table. While
Temp table:
lngStoreNumber - CAD_NAME - lngcomponentSerial
1 - "CHK" - a
1 - "STK" - a
2 - "CHK" - a
Main table
lngStoreNumber - CAD_NAME - lngcomponentSerial
1 - "CHK" - a - LEAVE (EXISTS In Both Tables)
1 - "CHK" - b - DELETE (lngStoreNumber & CAD_NAME composite Found /lngcomponentSerial NOT Found in Temp)
1 - "STK" - a - LEAVE (EXISTS In Both Tables)
1 - "RMM" - a - LEAVE (lngStoreNumber & CAD_NAME NOT Found in Temp)
2 - "STK" - a - LEAVE (lngStoreNumber & CAD_NAME NOT Found in Temp)
2 - "CHK" - b - DELETE (lngStoreNumber & CAD_NAME composite Found/lngcomponentSerial NOT Found in Temp)
3 - "CHK" - a - LEAVE (lngStoreNumber = 3 Not in Temp table Subset)
Rule: Only delete the records for a particular CAD_NAME and lngStoreNumber from the Main table leaving all other CAD_NAME/lngStoreNumbers.
I'm running these updates in batches of lngStoreNumber. So the Temp table will only contain subsets of what's to be deleted from the Main table thus the need to link on the key fields only NOT to delete a Subset of lngStoreNumber/CAD_NAME. I think I've tried every possible query that doesn't work.
Here is query #1 to insert records missing from the Main table that exist in the Temp table. I think what I need is a variation of this???
SELECT D.*
FROM Main AS S RIGHT JOIN Temp AS D ON (S.CAD_NAME=D.CAD_NAME) AND (S.lngcomponentSerial=D.lngcomponentSerial) AND (S.lngStoreNumber=D.lngStoreNumber)
WHERE S.lngcomponentSerial is null AND S.CAD_NAME is null AND S.lngStoreNumber is null;
THANKS.
View 2 Replies
View Related
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
Jul 21, 2006
I am rebuilding an application for a client and I have an Access table that I am using as a temporary table. Once the user is done entering information into the temporary table through a form, the user presses an update button that appends the records using an Append Query in Access to an SQL Server Table.
The following error message occurs:
"ODBC -- insert on a linked table 'linked tblname' failed.
[Microsoft][ODBC SQL Server Driver][SQL Server] Explicit value must be specified for identity column in table 'linked tblname' when IDENTITY INSERT is set to ON. (#545)
I am using a form, subform combination to record a bill with many details. The bill summary is posted into a tbl_TransactionsMain table in SQL Server using the ADO AddNew method. The PK for the tbl_TransactionsMain is then entered into the temporary table in Access. When the temporary table records are appended into tbl_TransactionDetail the error message occurs.
What is also interesting is while typing out this post I thought to test the error by manually trying to run the query. The query worked like a charm! :confused: When the orginal error occurred off of the form I tried to run the query manually and it failed. I am guessing that this might have something to do with the ODBC timeout.
I think SQL Server/ODBC connection is not liking how I have a set of records in an Access table with foreign key numbers assigned when I am attempting to append the records. I am new to SQL Server and any ideas are most appreciated! :)
View 1 Replies
View Related
Oct 27, 2014
I have an Access database, where one of the tables is near the maximum amount of fields (241 of 255), was just wondering if I could set up a secondary table that would be linked to the original table by a specific field and would store the other fields that would like to add to the table.
View 7 Replies
View Related
Jun 28, 2005
I want to append records that I have created in Table1, via a form (Form1), to Table2, using Form1's OnClose event. (Table2 will be amended later, but I need to preserve Table1). Is there a way to append only the records from Table1 that haven't been previously appended to Table2? Also, can I turn off the warning messages in an append query? TIA
View 9 Replies
View Related
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
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
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
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
Mar 21, 2014
I have a form with a listbox that displays the name of a table. Once the listbox item is selected, the table name is set to a variable called myFile. I want append the records from the table (myFile) into another table.
View 1 Replies
View Related
Sep 24, 2005
Hi,
I can't seem to get this right...any help much appreciated:
I have a two tables LESSON<PAYMENT (One to Many)
LESSON
Lesson_ID (PK autonumber)
Lesson_Date (Date)
PAYMENT
Payment_ID (PK autonumber)
Lesson_ID (FK)
Payment_Date (Date)
I am maintaining LESSON using a simple form. On creating each new LESSON record, I also wish to insert a row into PAYMENT, using values from the LESSON table - Payment_ID(autonumber), Lesson_ID = LESSON.Lesson_ID, Payment_Date = LESSON.Lesson_Date
What is the best way to do this?
I have tried to add an Event Procedure to 'Before Insert' but I can't seem to get the syntax correct. Also, for this to work, do I need to paint all fields on LESSON form including (hidden) PK?
I have simplified the tables above but they are relevant to what I am trying to do. Any help would be much appreciated- am new to Access...rather frustrating.
Many thanks,
Simon.
PS I have searched through existing messages but can't see one that answers this, I apologise if this has been answered before- just point me to the orig post.
View 2 Replies
View Related
Apr 19, 2013
Here's a query that the bottom listview in the attached form i.e. a listview representing a table of calls(many) to fims (1 top listview)
Code:
SELECT calls.id, calls.firm_id, calls.called, calls.said, calls.spoke_to, calls.next
FROM calls
WHERE (((calls.firm_id)=[firms].[id]))
ORDER BY calls.called DESC , calls.next DESC;
When I run the thing...I get a dialog asking me for firm id.
I want to change this so when I move up and down the firms LV (top)... the bottom LV updates taking firm id from the top LV with focus.
Access 2003.
View 2 Replies
View Related
Jun 26, 2007
I have a problem... I have four tables(but my problem is limited to just two)
The tables are Orders, Customers, Items and OrderedItems
The two more detailed below creates the problem when trying to copy an already existing order to a new since the customers usally order the samethings over and over again.
Orders
IDOrders
IDCustomers
strSalesperson
strWhen
strSent
OrderedItems
IDOrderedItems
IDOrders
IDItems
iNumber
bPacked
So I have made a copy button on the order form. The copy button should do this:
1. First save the old orders IDOrders and IDCustomers (which it does)
2. Create a new order with old data (which doesnt do)
3. Copy all post in OrderedItems with a new IDOrdered using INSERT INTO and using columns
My SQL statement is like follows:
sSQL ="INSERT INTO Orders(IDCustomers, strSalesperson, strWhen, strSent, strComment) VALUES (" & itmpIDCustomers & ",'" & strSalesperson & "', '" & strWhen & "','" & strSent & "');"
But the reply I got is "Could not find output table 'Orders'" but I have checked the names over and over again but it doesnt work.
View 1 Replies
View Related
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
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
Dec 25, 2014
i have two data tables, one is depending on the other. now i need to delete the main table row depending on the subtable row if it is null.
View 3 Replies
View Related
Nov 28, 2007
Hello people,
I have for some time now been fooling around with a database to keep track of several clinical trials
Basicallly I have made 4 tables..2 which defines the project ( Project and visist), 1 that populates the projects ( patients) and 1 that bind the patients visits to specific dates ( appointment)
The trouble is that im Lazy :D and therfore dont want to enter the appointment data for all patients one at a time each time we get a new guniea pig since all thats diffferent is the dates he/she has to show up.
Im hoping for some way to fill up my appointment table based on patientID and projectID alone.
SO this is my 4 tables... ( some unimportant fields left out)
Project
ProjectID (PK)
ProjectName
ProjectDescription
Patients
ProjectID(FK)
PatientID(PK)
PatientName
patientScrnr
Visits
ProjectID (FK)
VisitID(FK)
VisitName
VisitPrice
DaysToNextVisit ( integer)
Appointments
VisitID(FK)
PatientID(FK)
AppointmentDate
AppointmentID ( PK)
The idea is to create a project and then add a set amount of visits to the project ( days when they have to come and get a blood sample taken)
All patients involved in the project is likewise added in the Patients table and joined to a project.
Since the patients all have to come to a fixed amount of visits ( determined by the project) I was thinking I could make a form where I pick a patient from a combobox
(select projectID,PatientID,PatientName) and then automatically generate a record for each visit in my Visit table where Visits.ProjectID = cboPickPatient.ProjectID
and show them in a subform so I can enter the date they have to come. I hope that makes sense. ( preferably I would like to add the date also by just entering the first Visit date and the using the DaysToNextVisit to make the other visit dates or each patient, but thats a whole other problem :o )
My instinct tells me I have to do some sort of loop code but I havent figured out the details.
Can any of you guys lead me in the right direction before I loose all my hair in frustation??
This seems to me to be a pretty simple problem-making a recordset based on a projectID and the visits involved in that project but im just out of ideas:confused:
Kind Regards,
Brian Bj
View 5 Replies
View Related
Mar 9, 2006
Hi all, don't know if this is possible, but right now I'm running a query and then performing Dmin/Dmax on each record in the recordset and it's running SLOOOOW. Perhaps if I can get it from a query it would be faster.
I have Table-A and Table-B with a one to many relationship. In the Table-A I preferably need to return only one row per record. From Table-B, I need to return the minimum and maximum record that corresponds to the ID in Table-A.
I am familiar with min and max, but it the join methods I've been using either return multiple rows per ID or none. Any way around this?
View 2 Replies
View Related
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
Feb 6, 2013
I have Office 2010 working on XP Pro SP3.
This is the first time I have tried to append/import a bunch of names and addresses from a spreadsheet into my access table.
I thought it would be easy with all the integration of applications but it's not. What happened to the bit where I could match the fields where it's not quite the same name and set the type so it worked OK.
All I seem to be able to get at at the moment is a wizard which does a very poor job and won't allow me to append the records. I tried exporting the Excel as CSV - same thing - error messages.
Is there a way of matching up the fields so everything works? What am I missing - this should be a cinch right?
View 3 Replies
View Related
Sep 3, 2013
I select records from a table based on criteria:
< Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("SELECT * FROM [tblLVRWrittenStatements] WHERE [tblLVRWrittenStatements].[seedrsID] = " & seedrsIDVar & "") >
I now want to append these filtered records to another table called ArchivedWrittenStatementsTable;
< CurrentDb.Execute "INSERT INTO [ArchivedWrittenStatementsTable] SELECT * FROM rst" >
Would be lovely except rst not recognised. Is there a way of achieving this without having to <addnew etc > looping through the records.
View 1 Replies
View Related
Jan 22, 2015
Is there a way to append a pivot table to a table or possibly make a query based on a pivot table? I need to get a count of Part Numbers and I need the average price for all these parts. Additionally I want to ignore a count of less than 3.
Also I am having trouble filtering on the count in the pivot table... haha, so I was gonna Query on it later on.
View 2 Replies
View Related
Jan 13, 2008
Okay I had an idea and I thought I might get ffedback as I am relatively new to this. I went through a period a couple of years ago when I used access alot and was becoming familiar with VBA etc but I havent touched it in 2 years so Im pretty rusty.
I am running a study and need to have to create a database that:
a. collects data about participants
b. Has a number of questionnaires (5), each of which can be filled out by participants.
THe main table has a number of fields that collects info about the participants the most important of which will be the ParticipantID - an automatically generated number which is my primary key.
In table 2/form 2 I will host questionnaire one. This will be linked to Table 1/Form 1 (Particpant Information) by this tables primary key - also the Participant ID. The relationship will be 1:1. Each participant can only have one Participant ID and will only need to fill out questionnaire one once.
Is it possible that when I add a new participant to the Participant Information table/form I also automatically create a record in Table 2/Form 2 (Questionnaire 1), as well as Table 3/Form3 (Questionnaire 2) and so on so that they have the same ParticipantID...?
I was reading a similar query somewhere else and they said to use the Form_AfterInsert Event command? Is this right (see here http://www.pcreview.co.uk/forums/thread-1687644.php)?
I feel a bit stupid but I am willing to learn and try new things Once I get started I think I will be okay. If you could steer me in the right direction it would be much appreciated.
View 12 Replies
View Related