is there a way to save a record in a table even if nothing is entered manually in the associated form? The primary key is automatically copied from the previous form.
I have 2 forms, each bound to a table. I would like to display the recordsets of the tables in a query. But this does not work, because if nothing is entered manually in my second form, no record is saved. Therefore the record for the query is missing and the entry is then missing in the query.
As a general rule, the need to write out blank reocrds is not required, but is also VERY bad idea.
Lets take somthing simple:
We have say some customers (table customers), and then say we have some invoices for each customer. (table invoices).
So, I can build a query to say list customers, and say their invoice numbers.
But, what happens if I want that query to ALSO include customers that don't have a invoice just yet?
We would not start creating a whole boatload of empty invoices. That going to not only mean we have a gazillion blank records, but then all kinds of issues will crop up (such as rules stating we can't create a invoice without a invoice number!
So, you find that about 90% of queries in such cases?
You build your query as what we call a left join. just think of say all the records on the "left side" table will show, and optional the child records (the table on the right side).
So, a table with a join from customers to invoices looks like this:
But, we want the left side records to show, even when no child record(s) exist.
So, right click on join line like this:
And now we choose this:
Now, you see a "arrow head" in the query like this:
Note the arrow head, and note the option you have when building that query.
So, it very common to build a query, and very common to build such queries that work without child records.
but, we did not, and would not start tossing in boatloads of blank/empty records for such operations. that just creates a mess, tons of blank records now start appearing in reports.
And it even worse, since then you can't for example make invoice number a required field. The more tables, the greater the mess of blank records you will require.
For example, for each invoice record, then I have a bunch of child invoice details records!!!
As you can see, everything is going to fall apart VERY fast if we have to adopt a concept of creating blank records throughout the database.
Think of the huge pile of records when we have 3 tables or even more in the query!!!
The solution is not to create boatloads of blank records all over the place in your database, the solution is to build a query that works, and one that works even when no child records exist.
So, regular join (or often called inner) means a child record must exist.
But, a lot of times we want all the rows and records from the "left side" table in above, and don't care nor require that child records exist or not.
Use + adopt a left join.
And another tip? Always drop in your parent table on the left most side of the query builder. Then as you add child tables (when required), you work your way to the right, and those multiple tables that you drop into the query builder will VERY often need a "left" join, since as you noted, records might not exist in those child tables.
You should be free to type in, add new customers as you wish. The fact that you have customers without a invoice (just yet) should not matter for general operation of your database.
Related
I've been trying to figure this out, but I'm struggling.
Working in Microsoft Report Builder (latest version), I have a table that, for the most part, contains general information from a specific table, which I'll call GeneralInfo. In that table, each person has only a single row containing information about that person. However, one of my columns has a one-to-many relationship with the rest of the row. I'll call this other column DetailInfo.
This table provides an example of the kind of thing I'm going for:
In this example, all of the white cells come from the GeneralInfo table. The Orange cell may include many rows of work history, and each entry includes multiple elements from the DetailInfo table, separated by Newlines. The two tables can be matched / joined on the ID value.
This may not be the best way to go about a report, but it's part of the spec I was given. I know this can be done, but I'm having trouble learning how. Can anyone help me out?
Edit - I just found out that another column is also potentially one-to-many. In the example table, it would be saying that the "Occupation" value comes from the DetailInfo table, rather than the GeneralInfo table.
In MOST circumstances, this would just be "Construction Foreman" over and over again, and we would only want to show that once. However, in rare circumstances, an individual may have multiple concurrent (differing) Occupation values that would have to be shown. Is that possible? Should I make that a separate question?
I took Soundappan A's advice and created a sub-report in the column that needed the extra data. This video was helpful to me in learning how to set that up:
https://www.youtube.com/watch?v=LhSitVAnhyc
I have looked and haven't found a method on here to do this. I am assuming my search is skewed and I just missed it, if this is the case, please let me know.
Anywhooo, I have a large and unwieldy report coming out of SAP every day. Because it will often have some strangeness, we import that into an Access database so we can keep an eye on the stuff we need in our department. I am using a combination of 6 fields to create a primary key in Access. The information in those fields is about the only thing consistent I get out of this SAP report, but the remainder of the data can be considered dynamic and can change from day to day. Usually this is a matter of filling in a few blanks, Occasionally this is changing existing data, and on rare occasions, it may involve deleting data out of a handful of fields.
The SAP report is around 130 columns of data, So I'm looking for an efficient way to roll in the changes without overwriting what folks put in there manually.
EDIT:
Here is the way this is used. SAP (for reasons I'm not going to go into) sometimes will have bad data show up in the daily report. We are using Access to track and put the correct data in to something that we can generate much more accurate summaries. What the users put in is to be considered true and accurate.
The transactions we are tracking can take a long time to complete. Most take around 30 days to complete. That's why I will have blank fields on one day, and several of them to be filled in on the next. We might not get any for the next few days and then a bunch more are filled in later. That is the normal flow.
What I have to account for is the odd occasion where a mistake is made early in the process. At a certain point, an error will break SAP's ability to update anything at all in the report we have to use.
I have 3 fields set up that trigger what my users daily work is going to be. There is a logical flow so that user 1 completes what he needs to do and then that record will show up on User 2's report. These fields will also stop the general update process in an exception report if there is a difference in what is coming in from SAP, and what is already in my database.
What I am looking for is some way to systematically fill in blank fields, on existing records in access. I do not want to overwrite if something is in a field, only the null values. I can do this on one field at a time, but each record has about 130 fields. I'm wondering if there is a way I could do this in just 1 query?
Thanks all! I hope the edit makes more sense now
A simple google for "Access SQL update null values" could have yeilded you what you need. But if all you need to do is fill constant values into empty fields then something like:
UPDATE Table SET Table.field1 = VALUE
WHERE Table.field2 is NULL;
Now if this data is different for each record based on; say data from another field, then you may need to write some VBA to build that value/string for you. But otherwise if you are JUST updating null fields to include data, then a simple UPDATE statement will do
EDIT Based on new info:
So if I'm understanding correctly: you have two tables. One table with the blank fields and another table that contains the values you need.
If this is the case, you can use a similar UPDATE statement, but use an inner join to get the data you need from table B to fill in table A
UPDATE TableA INNER JOIN TableB ON TableA.KeyField = TableB.KeyField
SET TableA.NullField = TableB.NotNullField
WHERE TableA.NullField Is NULL;
I'm trying to create a query that will return all of the customer ID's from multiple tables as well as the monetary amounts that go with each of the customer codes. However, instead of pulling in every customer code from each of the tables in the query, it only pulls in a random selection of the codes. Any idea what could be causing this to happen? I apologize if I explained it poorly, if you have questions ask away. I've also attached a snapshot of the query design view below.
query design image
You are using INNER JOINS in your query, which means only rows that exist in all joined tables are returned. So if you have a customer that purchased items in 2014 but not 2015, then their name will be excluded.
If I understand what you are attempting, you want to use LEFT or RIGHT Joins, which will return all rows from KNOXLIVE_SLCUSTM and only rows from the other tables when a match is found.
So if you do not know SQL, right-click each join line in the query designer, and select join properties.
Depending on which order the tables were initially added either the second or third radio button will be the join you want. Choose the one that selects ALL records from KNOXLIVE_SLCUSTM. Do that for all four joins and re-run your query.
Ok here is my dilemma and I am sure more experienced Access users have an easy solution. I have been manually running a set of queries to pull data for business users, that I want to create a form for so they can just run it themselves. This would be easy if it was one query, but the way I have to pull the correct data is first have to run one query that creates a table. I then use that 'new' table in a secondary query to get the data I need.
That first make table query needs to take inputs like supplier number and date range. I then use that output table in another query that sums up total dollar value of purchase orders. I can not include these two steps in one query as it creates an ambiguous outer join.
Any ideas on how I would go about creating a form for something like this?
Well after re-thinking this I think I was OVER thinking it. Instead of creating a table in the first step, I can just save it as a query and join that query to the second query. Then make a form off the two queries.
I'm designing an Access 2010 web database, and I'm trying to create a subform that will display data based on joined tables. It displays alright, but I can't modify the data. The two tables are called Consortiums and PrincipleInvestigators. There's a many-to-many link between them, so I have a ConsortiumsPrincipleInvestigators join table.
I have a "consortium" form which displays the data related to a specific consortium, and has a subform within that form that displays the principle investigators part that consortium. I was able to successfully all the PIs, but when I try to add a principle investigator within that subform, it gives me an error: "Cannot add record(s); join key of table 'PrincipleInvestigatorsConsortiums' not in recordset. What gives? I imagine it's because I need to update both the PrincipleInvestigators table and the join table. (Also, MS, why can't I just use standard relational database stuff instead of this silly lookup field business?) Here's some screenshots of my table layout and my join table:
http://i.imgur.com/j4RJQ.png
Bleh. I feel noobish although I've done a decent amount of database projects, but the lookup fields and query builder is throwing me off. Does anyone know of any good tutorials on how to design queries?
There is really nothing that changes in terms of building a relationship between two tables. The fact that you use a GUI, a SQL DLL command, or now some relationship wizard changes nothing.
I mean who cares what the process is much to setup a relationship between two tables?
I mean, in client based you could type in something like this:
ALTER TABLE Cars
ADD CONSTRAINT MyColorIDRelationship
FOREIGN KEY (ColorID) REFERENCES Colors (ColorID)
So, now you use some wizard that is a few mouse clicks and this is some big deal? Really, who cares! No big woopy here, all we care is that you execute some command, or some wizard, or something here and you at the end of your day the result is your beloved relation between the two tables.
Check out the following video of mine where I "hook up" some existing related data into a web database. And I ALSO share how you can printout the related tables using the Access relationship window for a web database:
http://www.youtube.com/playlist?list=PL27E956A1537FE1C5&feature=plcp
So, at the end of the day, no need to get twisted up in some details of having to use some DDL sql command, some GUI relationships window, or some wizard. All you are doing as the above video shows is hooking up some tables and setting up a relation – nothing more, nothing less to worry about.
As for how to add child records that are to be related to a parent record? Well, in the past for the last 18 years, quite much every bird, dog, and beetle using Access would simply do this:
a) Create a main form based on the ONE main parent record table. There is NO NEED to build a query here, and in fact NO need to build a query that is a join of the two tables – this was never required and is not required. All you do is build a form based on the one simple table. We are done this part "a".
b) Create a form based on the ONE child table. There is NO NEED TO build a query here, and in fact NO need to build a query that is a join of the two tables – this was never required and is not required. All you do is build a form based on the one simple table.
c) open up first form (the form based on parent record table) and then in layout mode, now drag + drop in the child form from the nav pane.
The above a,b,c steps is how virtually EVERY parent to child setup in Access I seen done, and this long time forever setup CONTINUES to work 100% in web based applications.
In both cases (web or non web), the setup remains the same, the setup does not involve building quires, and the setup does not require ANY coding on your part.
As long as the link/master child settings are correct in the sub form control, then you are free to add child records to the child form and Access will do the rest of the dirty work of setting up and maintain the relation for you by setting the FK column in that child form for you.
So, how the basic setup works here has not changed in 18 years of using Access, and as such this does not change when building a web form here.
You don't need a query based on more than one table, and in fact JUST like in the past, the two forms will as a general rule will have their data source based only on the one table.
So in most cases there was never a need to even use a query for that one table that the form is going to be based on. This long time basic approach and setup has not change for web forms either.
In your case I would assume the main form is Consortium. You child form could be a continues form based on Principleinvegiartors. And in place of having to manually enter some PrincipleInvetigaor ID, you use a combo box based on table PrincipleInvetgioars. However, again in all cases, we are simply building forms that are based on a single base table.
For this situation, you should choose one of your tables for the main form and the junction table for the subform.
For example:
Main Table
Consortiums
Subform
ConsortiumsPrincipleInvestigators
Link Child and Master Fields ConsortiumID
ComboBox on subform
Principal investors
Row source: SELECT InvestorID, InvestorDetails FROM PrincipalInvestors
Control Source: InvestorID
Bound Column: 1
Column Count: 2
Column Widths: 0,2
Some notes on Not In List
DoCmd.OpenForm "AddSomething", , , , , acDialog, AddData
If Forms!AddSomething.Tag <> "" Then
frm(cbo).Undo
frm(cbo).Requery
frm(cbo) = Forms!AddSomething.Tag
AddCombo = acDataErrAdded
Else
AddCombo = acDataErrContinue
End If
DoCmd.Close acForm, "AddSomething"