Pulling A Value From A Form To Create New Records In Append Query
Feb 27, 2006
So, I've been searching through this forum and can't seem to find the answer to this one. I would like to capture a value from a main form and have it used as a value in an append query, in order to populate a subform based on the main form, like so:
INSERT INTO tblTakenSurveys ( VisitID, SurveyQuestionID, ResponseCodeID) SELECT Forms![frmMyFormName]!VisitID, tblSurveyQuestions.SurveyQuestionID, 66
FROM SurveyQuestions WHERE SurveyID = 3;
Might help to explain some of the terms in this statement:
tblTakenSurveys is where I need the new data to be entered via the subform.
Forms![frmMyFormName]!VisitID is a textbox control bound to a PK in another table that has a one-to-many relationship with tblTakenSurveys.
tblTakenSurveys.ResponseCodeID is a foreign key that represents respondents actual answers to questions.
66 is a value for a ResponseCodeID that stands for a dummy value meaning "data not yet entered"
As per advice I received from others on this forum, I have set a query like the above to run from a command button to populate the subform (in theory). But I'm sure I've done something wrong within the query because it will not return a value from the form "VisitID" control and therefore will not append the rows. Without the appended rows, my subform will not populate. And this has me running in circles...
I pasted the link to another thread below, where I originally received a lot of input as far as the table structure. I did not start this one, but my posts are the most recent (as of now anyway). Pat Hartman had given me a lot of the guidance here.
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.
I am creating a database for users that no nothing about access nor do they want to learn. So the database needs to be as simple as possible.
This being the case I would like to avoid users from creating/editing querys.
I would like to have a form that would run the append query. The query would have a date column and a status column that the query would filter.
The query would have a criteria for status that would equal to "BACKED OUT" and the date would need to link to the two text fields on the form. My problem is writing the VBA code to make the query append in the background.
For sake of argument: Query = qryappend Form = frmappend Table = tblappend
Apologies if this is really basic - I am trying to write a query to show all records from table A linked to table B so that if a field is blank in table B, it will show. At the moment, every time I run the query, it only shows me records which have entries in both tables. (They are linked by ID no). ie there are 77 records in table A. Only 23 in table B but I want a query showing which ones in table A do not have something in field "x" on table B. Does that make any sense ? As ever, I'd be ever so grateful for help.
While I'm at it, does anyone know anything about getting a database to produce reminders ie based on date entered, highlight when 3 month review is due ?
In the Owner Name field, I am looking for a way to pull out all estates. They are abbreviated with "EST" or "Estate". The problem is throughout the database, if you do a simple filter for "contains est" it will include names such as "Forester" or "LHB Investments".
How do I query, or filter this database such that it only returns the estates abbreviated with "EST" or "Estate"?
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.
Each customer has many projects. My ultimate goal is to create a table like this:
Table C: - Customer - Project - Customer Industry
Trouble is, tables A and B are updated by different persons. A project is usually created first before someone creates the entry in Table A to enter the customer's industry. If someone forgets to update Table A, I will see entries in Table C with industry of customers as blank - which i don't want to. What is the best way to do this?
I'm thinking of running some sort of queries that will automatically create an entry in Table A when a new customer project has been entered in Table B, so that the person responsible for Table A knows to enter in the industry - but i don't really know how to start, could you help please?
Hi, everyone. I've been reading this forum for several days now and the information I have picked up here has been wonderful. Thanks. Unfortunately, I haven't been able to find what I'm looking for on a problem I'm having. I apologize for the long post, but I wanted to include as much information as possible. Thanks for taking the time to look at my problem.
My Background: I am a Computer Managed Maintenance System Planner for a foundry. I am responsible for the administration of all maintenance and repair records for the plant’s mobile equipment (dump trucks, fork lifts, etc.) I’ve been using Access as a report writer for several years. I have pretty good understanding of report writing and basic query writing, although I have never used pivot tables or crosstab queries, and I have only used amend/update queries a few times. I have a novice’s understanding of relational databases and I recently picked up a book on VB for MS Applications and have been devouring it. The rest of my limited VB knowledge comes from reading these forums, so my programming knowledge is still in its infancy.
What I’m Using: I am on a network that uses Windows 2K, to which I have only regular user privileges. We use an Oracle database (it is used for everything in the plant) with a third party CMMS. I use Access 2002 to do my report writing. I have a small database set up that contains links to the necessary tables in Oracle and a few tables I created to help “massage” my data for queries and reports.
My Problem: Our CMMS app is only set up to retain the current and the previous hour meter/mileage readings. I need to be able to retain all my hour/mileage readings, however, so that I can track up/down time, utilization, etc., over several different periods of time, including years.
What I Want To Be Able To Do: I want to archive my hour/cycle readings in a table so that I can reference them for later queries and reports. A couple of typical questions I want to be able to ask of this information are 1)“What was the last known hour/mileage reading for this/all equipment on <date>?” 2)“How many hours/miles have passed between <date1> and <date2>?”
What I Have Done So Far: I’ve done research into crosstab queries and pivot tables. I don’t fully understand these, but they don’t seem to be what I’m looking for. I could be wrong, though. Then I got to thinking that the easiest thing for me to do might be to make a button on my main form that would run a query to append the hour data from the db to a table I made to store the info (tblMeterArchive). The table would have a column for the Equipment# and then the append query would create a new column with today’s date as the heading and dump the data into it. The problem is I can’t figure out how to get a query to add a column to a table and stick today’s date in the heading. I’ve searched these forums and I’ve done a Google, to no avail. I have even taken time to just start going through every thread to see if this sort of thing has been discussed before. So far I haven’t found anything and my boss is getting a bit peeved at the hours I have spent working on this so far this week.
So, my question is can an append query create new columns in a table? Or, am I barking up the wrong the tree and there is a better/easier to accomplish my goals? Even a link or pointer to the proper way to search for the information I need would be much appreciated.
Thanks again for taking the time to look at my problem.
I am trying to create a query to append new records from my NEW database into my old excel database.....
The old DB has 4-5 extra tabs that the NEW database does not have so when I append, in those extra columns the new database will just have blank records since the column doesn't exist.
Usually I do a append query in design view. but sometimes it gets funny because it creates duplicates...
How would I go about it, so its quicker and persistent like creating a macro excel.
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?
I am trying to create a query that takes values from a search form and provides records. I was having issues with getting results when some boxes on the form were left blank. I found a solution to that and it worked with a small number of fields. However when I make the full form query (about 8-10 fields) and run it says the query is too complex. I wrote the sql as I could not get designer to do what I wanted. Attached is the sql that works and that which is "too complex".
I have several (about 10-15) queries that I have designed to run monthly reports. Various pieces of the criteria for each query need to change regularly. For example, in design view, I currently have a 'Where' field for each of our eight products. Where 1= include the product in the query analysis. Where 0= do not include the product in the query analysis. We would like to have a form that has entry boxes for each product where the person doing the analysis could type '1' or '0' and then the query could update the criteria entered before running.
We also need dates to update via the form. I currently have [Current Period End Date] and [Prior Period End Date] pop up boxes on each query that allow the person running them to enter their desired dates. But again, my boss wants to limit their involvement with the actual queries. Plus, you end up entering the dates for all 10-15 queries, which is a hassle. We would like to have entry boxes for the desired dates in the form and have the queries pull date criteria from the form.
If we can pull query criteria directly from a form, is it possible to create a table from a form and then pull the query criteria from the table?
I'm trying to update a record in a table, from a query that is run as part of an event from a command button on a form.
I have a table called 'Assets', a table called 'Disposals', and a form called 'Disposal Entry'. I would like the user to select an Asset ID from a combobox on the form, then when the button is clicked it adds a record to the 'Disposals' table, and updates the Status for that specific Asset in the 'Assets' table to "Disposed".
It adds to the Disposal table fine, but I can't get it to update the Asset table.
My query looks like: Field: Status Asset ID Table: Assets Assets Update To: "Disposed" Criteria: [Forms]![Disposals Entry]![Asset ID]
I've checked the spelling and everything looks ok.
The [Asset ID] control on the form is bound to the Assets table. If I edit the control and clear out what is in Control Source, then it updates the table and works fine.
However, I want to keep it bound as I have a subform on my home page showing the latest disposals.
How I can get the query to use the Asset ID on the form as the Criteria?
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)
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
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?
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.
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;
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?
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.
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.
I'm using an append query that needs to add the records from another database into a table. I can get it to get the data and add the records. There are other columns in the database that are not in the one the data is pulled from. If I would run the append query again, it would add the same records again at the end. How can I avoid this? I only need to add new records that are not yet in the database I want to pull the records to.
I have an append query that everytime it runs it will simply duplicate the records. ex.. sample table has 11 records if you run it again the tableB will now have 22 records. I need it to only update the records, so if someone makes in change / new record in tableA it will only update the records in TableB. I have the Primary Key set to Yes no duplicates. TableA Primary Key is ID TableB Primary Key is CustomerID
- 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.
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.