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"
Related
Why would my form/subform mislink records using SharePoint List back end?
I have years of experience with MS Access, but this is my first time with SharePoint List as a back end.
I developed a small database for a small non-profit. Started off with Access 365 front end and back end, located on one user's computer. This ran fine and correctly for a few months, and last month we migrated the back end to SharePoint Lists so that two other users can use the database. They each have the front end on their desktop.
There's a bound form, Events, linked to tblEvents. Subform, subVolTime, on this form is linked to tblVolTime, to show the volunteers and how much time they spent at the event. In the subform property, Link Master Fields is set to tblEvents.ID; Link Child Fields is set to tblVolTime.EventID. There's no extra VBA code.
We migrated to SharePoint Lists using the wizards, and did nothing else. Shortly afterwards, my user noticed that the wrong people were showing up under events. He can tell just by looking at the names.
I created an audit query, and I can see that in some cases the dateAdded (date the record was created) in tblVolTime is BEFORE the dateAdded of the event in tblEvent. This can't be right, because you must have a record in tblEvent before an associated record in tblVolTime.
For example, there's an event ID 261, created on 4 Nov 2021. The records for the volunteers linked with this eventID were created 7 Oct 2021. Something went wonky.
Any suggestions are welcome. My ideas include: unbind the form; hide the subform until the event record is saved; create the event record before the user actually adds any data to it.
Well, hard to tell. However, unlike moving Access data say to SQL server?
Moving data up to SharePoint is VERY MUCH a different process. Why?
Well, for one, when moving data to SharePoint, the auto number PK's you have (and you MUST HAVE FOR ALL TABLES) are often re-numbered.
Now, due to this re-numbering of auto numbers?
Well, that means before you migrate the data, you BETTER really, but really and beyond really sure that a relationship was setup between such tables.
In the case of Access, while in most cases we do have a correctly setup relatonship, to be honest, you REALLY never had to do that. In other words, if I setup a master link and child link for a sub form? Well, access would just generate the PK autonumbers for the main table, generate the pk autonumbers for the child table. And THEN during a data insert would correctly insert/set the "FK" values in that child table to the parent table. As long as the link master/child settings were correctly setup (but no actual relationship was setup), then the application would happy work.
If one was to migrate the data to say SQL server? Well, since the PK autonumbers are NOT touched during this up-load process - then all relationships and their data would ALSO make a valid trip up to SQL server.
However, in the case of SharePoint? Autonumbers for ALL tables are and will and in most cases are re-generated!!!!
But, this tends to not be a problem if you up-sized the data using Access. It has built in SharePoint support, and say if a parent reocrd goes up from Access to sharepoint and the PK id is changed? No probem, since if you REALLY did setup,and you REALLY did have a relatonship setup, then the migration process is smart enough to go find the child reocrds, and update the FK values. But of course the migration process can ONLY do this magic trick if you KNOWS about the realationship.
Another simple example?
Say we have a simple form, and we have a SMIPLE combo box to pick say favor color.
tbColors
ID (Auto number PK).
Color (text color).
So, so now we have a simple form, and we dropped in a combo box. When we choose a simple color like "red" or "blue" from the combo, we of course are saving the "pk" id from the above table.
Now for a LOT of simple tables like above, never used, or bothered with setting up a realtonship. (no need - just a few choices from a combo box).
And if you were up-size data to sql server? Again, this would work fine - no problem at all.
However, if you up-size to SharePoint? You REALLY but REALLY better have setup a relationship even for this simple silly little combo box. Again, the reason is simple. When that simple table of pick list values goes up to SharePoint, the autonumber PK id's will change. And thus for any other table that used that simple pick list? You have and MUST have setup in your relationships window that this was in fact the relationships - and again, the reason is re-numbering of autonumbers.
So for ANY relationships that used PK and FK values? They MUST in ALL cases when using SharePoint MUST have been defined in the access data tables (relationships window) BEFORE you transfer that data. And again, the reason is simple - during a up-load process to SharePoint, autonumbers WILL CHANGE!!! And since they change, then any other dependent table that uses those PK values (as a FK) MUST have been part of a defined relationship. If they are not defined before migration to SharePoint, then a change in a PK value will NOT tell SharePoint to go and find and correctly update all of the "child" records or so called FK values.
So, the first question to ask is did this break in related numbers occur a long time ago (at migration time), or did this break occur due to some bad code, or the wrong values having been selected?
So, migration of related data to SharePoint is a "delicate" operation, and the main reason of course is that the related tables MUCH have been setup as enforced relationships BEFORE you migrate. If such relationships were not strict defined, then during the migration process then the relation of data based on those PK/FK values will break at that migration time.
Now, it could be a simple issue that this sub form in question does not have the correct link master/child settings - that's the first thing to check.
I have a parent form (frmGroupSession) that has a subform (SubFormParticipants) in datasheet view. The subform is based off a query that selects all participants ([CLIENT ID], [NAME], [ATTENDED]) that had attended a specific group [GroupID] on a specific date [GroupSessionDate]. The parent form saves to a table that logs group sessions (tblGroupSessionLog). I need to save the group's participants [CLIENT ID] to the record within tblGroupSessionLog
Basically, I need to pass data from the subform to the record within tblGroupSessionLog. I'm not sure what the most effective way to do this, if it's possible at all. Ideally, I would like to have each unique participant [CLIENT ID] stored in its own field within tblGroupSessionLog. If there were 20 participants in the subform then each row value from the first column/field [CLIENT ID] would be passed to the corresponding field within tblGroupSessionLog ([ClientID1] thru [ClientID20])
I am relatively new at this. Even asking the question was difficult.
I am not sure what else I can provide to help you wizards with the solve, but let me know and I will.
Thoughts? Ideas?
Access 101 : You have a many to many relationship You should look that term up but in short it means clients can belong to many groups and each group can have many clients. (so bang your data into a normalized structure similar to the following:
First tip make sure to add the relationships under database tools (you should look that up). Access needs to know how the tables are related to manage the keys behind the scenes and sometimes access makes better decisions about automatic form creating when it already knows the relationship structure. Once your data is properly structured access makes it easy to produce functional if much less than styling data entry forms which can also be used as even worse search forms. For instance Click on any table and hit create form on the ribbon and access will create the data entry form form you.
Basic Style tip 1: Always delete primary key fields like ClientID from the form. The field is still there in the form's record source being managed by access. Users almost never need to see any table keys. This gives you a basic data entry form which you can also use to scroll through any clients you have entered using the record selector circled at the bottom of the frmClients.
Play around with the record selector to see how it works. In particular go past the last record and you will find you can enter new clients and access will automatically give them a ClientID. You can also cycle through your Clients and update them using this form it just isn't stylish. In the same way we can make a form for the groups table.
You make a form for the frmGroupSessions table in the same manner as the others but add a step. Replace the text boxes holding ClientID and GroupID with human readable comboboxes. Here is a link to help with that: https://www.google.com/search?q=access+change+text+box+to+combo+box&oq=access+change+text+&aqs=chrome.0.0i457j0l2j69i57j0j0i22i30l2.7503j0j1&sourceid=chrome&ie=UTF-8#kpvalbx=_r0sFYJ7vBcfY5gLz2aTgBw15
Becomes:
At this point play around to learn. Use the Record Selector at the bottom of frmGroupSessions to add and modify data. Play with the Tables and see what happens. Start messing with the form properties in particular the default view. Soon you will have ideas about how the form could be better and you can start figuring out how to style them.
With my limited knowledge of Access, I have been struggling to figure this one out.
I have 4 tables. tblJobDetails, tblDrawings, tblDrawingFixtureType and tblFixtureType. They are related to each other in that order.
What I have been trying to do is a query based from tblFixtureType. I want my users to have a datasheet where they can input all the fixture types for the given job, but keep them under that particular JobID. I have not had much luck in that department. All queries I have made either show every single type entered in the DB, or nothing.
The JobID is the PK for tblJobDetails and is a FK in tblDrawings. tblDrawingFixtureType is intermediate/junction table that is meant to hold quantities, but has DrawingID and TypeID as its FK's.
So how would I correctly build a query for my users to input all fixture types (designations), but keep them assigned/filtered under that particular JobID?
I am sure more info will probably be needed, so please ask.
You don't build a query to solve this problem. What you do is build a form based on each separate table.
In Access you model the parent to child relationships by using form + sub-form combos.
So, you might have a form that say lists out job (continues form).
You click on a row, and then launch a form with a nice display of the job details, and then in the sub form, you allow entry of tblDrawings.
The sub form will hook up the FK. And to edit/select the tblDrawingFixtureType, that drives a combo box in that sub form to select the fixture type, and it will save the PK of FixtureType in the one column.
All and any of each form (or even the sub form) is to be based on ONE table, and NOT a query. You don't edit data in tables, you build a form based on the table. If there is child records to add to that one record, then you build a sub form (and again, that sub form is based on ONE table).
Not only does this mean you don't have to create any queries, but you also don't have to write any code since when using a form + sub form, you get editing of related data that way.
Can anyone provide me the steps to create a form that is based on an SQL Query. I have already compiled a form using the wizard and am working to figure out how to do it based on a SQL Query. As well as using my own design to create a form using a master detail relationship.
What do you mean by SQL query?
Do you wish to bind the form to a recordset? If so, see http://support.microsoft.com/kb/281998.
Do you wish to use an SQL Server view for the Record Source? You can link it: http://office.microsoft.com/en-us/access-help/import-or-link-to-sql-server-data-HA010200494.aspx
Do you wish to set the Record Source to an SQL string? You can do this manually or through VBA.
Actually you are probably mistaken in your belief that when you build a master form with one record, and then want to edit some child detail records in access that you have to build a query that joins the two tables together. I can't stress how wrong this is, and that's not the way most systems will work.
In fact if you are to join the master record to the child table, if you have 10 child records, the master record would also be repeated 10 times in that query, and which of the 10 reproductions of the master record would you thus want to be able to edit?
So you are most certainly free to build a query that's based on the master table, and that query does not need nor is there any requirement to join in any child record data. Once you build this query, then you are free to use the wizard or simply bring up a form in design mode and drop fields on into the form based on this query. When you've done that you can save this master form. You now can then build a new query based on the child table. And then again you now build a form based on this child table. Once you've done this, then you can drop the child form into the master form, and you have the same setup as to which the wizard has accomplished.
So in both cases and both approaches there's absolutely no requirement to build a sql query that joins in other tables. And there's really no particular advantage or even performance advantages to building and basing a form on a query as opposed to the base table. And for the child form that edits the child table, once again there's no particular advantage or performance issues by basing the child form on the child table directly, or basing it on a query.
So in access to model and edit and maintain parent to child data or master to details as you ask, you DO NOT have to use queries that join in the two tables. So as a general rule will base the form on an query that is the result of one table. As noted it's rather, and an acceptable to base the form directly on the table itself.
I'm trying to build a database for a hospital program. I have two tables that are related in a parent-child relationship. I have a form to add new records (records that dont already have a parent record) and I want to build forms that allow me to view all of a parent record's "children" as well as allowing me to edit them. I want this form to allow me to search for a record in such a way that only one parent record can be
returned.
Please see my database at http://rapidshare.com/files/283207434/IC.mdb.html
-check the form called "TEST". I can't get it to work so that the main form controls can act as filters to display the child records in the subform. I have been to many many forums and my lack of knowledge makes forum tag almost useless. A friend told me that this service was fast! If there is someone out there willing to help this poor soul over IM or something, that would be terrific! But I'm willing to work with you here too :) Hope to hear from you soon!!!
-Thanks
Zorkmid
There isn't really any code involved. From what other forums have told me, I don't need any code. Here's what a MS MVP said. I've tried all that, and I cant pinpoint the errior.
Build you main form based on the main (parent) table. DO NOT use a sql join
to bring in child records. Simply build a form on this main table.
To have the form "jump" for move to selected name simply use the combo box
wizard and drop in a combo box (follow the instructions).
Now, create a continues form based on the child table. Again, you can build
this form and base it on the child table. Again, don't use a sql join, nor
try to bring in any fields or parts of the parent table.
It is assumed you also correctly setup the relationship between the two
tables in the relationship window.
Now, bring up your "main" form (the one based on the parent table) in design
mode. Make sure wizard are enabled, and then drop in a sub-form control and
follow the wizard instructions (choose the correct form based on the child
table). Ms-access will setup this for you.
The end result is that if you navigate in the main form, the child form (sub
form) will follow and display the correct child records. and, in place of
using the navigation, if you use the combo box created by the wizard, then
again when the parent form move to a record, the child form will display the
correct records.
All of the above can be done without you having to write one line of code.