populate a many-to-many table with access - ms-access

I have two tables (persons and projects) which are in a many-to-many table, thus linked together by a third table persons_projects
In ms access I now created a form showing data from the projects table.
What I want is to have a subform showing all persons- datasets which participate in this project. In this subform it should also be possible to add (or delete) persons from this project—a drop-down seems the best choice here.
How can I do this? I’m able to show all participants, but I’m not able to add them. seems like I have the “insert into view” problem again, since I need persons and persons_projects to show the correct datasets. but as I’m only changing/adding rows in a single table (persons_projects) I don’t see why access is bitchy again.

You should not need persons, only persons_projects. I assume that persons_projects consists of:
person_id -> FK ) Combined as PK, perhaps, if not, an autonumber PK
project_id -> FK )
and (recommended) a datetime stamp and user field.
The subform is set-up with a Link Child and Master Field of project_id, which will be automatically completed by Access, and a combobox similar to:
Control Source: person_id
Row Source: SELECT person_id, surname & " " & forename, some_field FROM persons
Bound Column: 1
Column Count: 3
Column Widths: 0cm;2cm;2cm
Edit re Comments
It is possible, though often a little more difficult, to include both tables and have an updatable recordset, the query (view) should include both project_id and person_id from the junction table.

Sounds like persons is the driving dataset here since you want to be able to link it to multiple projects as well as delete the person record.
Base your form on the Persons table. A subform should be based on the person_projects table and linked by the corresponding id's. You can use a combo box on the projectid in the subform and have some other field displayed so the user can identify the project (name?). You may want to show all the project data for each project on this form, but you may find it getting very confusing to the user. Having a separate form that you can 'pop-up' to give more project information may be a better choice.
If you want to delete a person, you can just delete from the persons table, but you need to decide if you want any orphan records in the person_projects table (Which you shouldn't). It's easy in Access to establish a link with referencial integrity (cascading update and delete optional). It's up to you as to how robust this needs to be.

Related

How to relate one table with many other tables in Ms access?

The database i'm trying to create have four tables. tblPatient information, tblparasitology tests, tblserology tests and tblbiochemical tests. All the later three tables are related to patient information table. What i want to ask is that, is there a problem if i use the primary key in the table patient information to foreign keys of all the other tables? in other words how many tables (foreign keys) can be related to a primary key on one table?
There is really no practical or particular limit here.
however one tip, one concept to keep in mind?
While you can setup all these related tables, to create forms that edit the data?
Each form is STILL based on the one base table.
So you can create a form based on tblPatients.
So allow view and editing and adding of say tblserology results?
That will become a sub form. NOTE VERY careful here that the form tblPaitent is based ONLY on that one table. And the child table (and child form (ie: sub form) tblserology will ONLY be based on tblserology table. So the forms to hook up, wire up the relatonships between the tables are STILL only based on the single table.
To allow editing of related data, you thus use sub forms. If you do this correctly, then no code is required to edit and display and maintain say display of test results for a given patient.
So each and all tables will have a primary key (auto number id).
To realate a child table back up to a parent table, you create a plane jane long number column. This value will be automatic setup for you if you follow the above advice for a main form, and then a sub-form for the child table data.

Trying to update record with a form, error: "The changes you requested to the table were not successful because they would create duplicate values..."

I'm creating a database that will be used to keep track of maintenance performed on equipment in a nursing home. I'm using MS Access 2010, and I'd say my skills are somewhere between novice and intermediate, almost entirely self-taught for this project.
The database structure is as follows:
tblAssetTypes:
TypeID (PK),
MaintenanceSchedule,
EquipmentType,
EquipmentSubgroup,
MaintenanceTime,
TasksRequired
tblUniqueAssets:
UniqueID (PK),
StorageLocation,
TypeID (FK)
tblPrevMaintRecord:
ID (PK),
UniqueID (FK),
DatePerformed,
TimePerformed,
MaintenanceComments
The UniqueID will be an identifier created by maintenance people, usually as four letters and then three numbers. I'm currently using "test001", "test002", etc.
I have a form that allows users to enter the UniqueID that has been assigned to an asset, select what kind of equipment it is, and where it is stored.
I'm currently creating another form which I want users to be able to select from a list of pre-existing UniqueIDs and then change the location that is stored in the table. However, as it is currently set up, every time I select a UniqueID from the combobox on the form, I get the following error. This error comes up after I have selected an UniqueID, and then if I try to do anything further, such as saving the record or even trying to close the form.
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key, or
relationship. Change the data in the field or fields that contain
duplicate data, remove the index, or redefine the index to permit
duplicate entries and try again.
I'm sure I probably need to give more information but I'm not sure what will be needed so I'll edit as needed.
How can I update the location information stored in tblUniqueAssets for a UniqueID value that already exists? Surely I wouldn't need to delete the record first and then create a new one with the previous UniqueID?

MS Access 2013 query query criteria can't assess if value A is contained in value B string

Issue:
I am developing a simple issue tracking database and have hit a stumbling block that I’m not sure how to resolve. Have tried several approaches using queries, sql statement etc but still not working. I may have to rethink how I am doing this but hoping someone may be able to address the issue as it stands, though if a more elegant way of doing it happy to implement that.
Scenario:
A table called tblUsers has a field called Access that is a lookup to a table called tblCategory and allows for multiple values to be stored (one to many). In essence this is saying which category(s) of “issue” the user is allowed to
A simple msgbox test in code shows that this is correctly storing the values selected in the following format "1, 2, 3, 4"
In turn, each issue can only have a single category (one to one) which is stored in a field called Category in table tblGMPIssues and is also populated from a lookup to the tblCategory table.
So far so good ….
I then have a query called qryUserIssues that should show all issues from the table tblGMPIssues that are a) “Open” (status = 1) and that b) match any of the categories that the user is permitted to view.
I can get this to work with a single value i.e. as it stands query prompts for input and if you enter a single valid integer it returns expected results
But I can’t work out the syntax to get the criteria to accommodate multiple values. For example, in above scenario our user should be allowed to see 4 different category or calls “1, 2, 3, 4”
Tried using INNER joins, tried assigning to variables and using a LIKE criteria but can’t seem to get the syntax right.
If anyone could let me know if this can be done and if so how as it’s driving me nuts.
All help and suggestions gratefully received.
Updated relationship diagram --> 1
For precisely the reason that you've asked this question I would recommend never using the multi-select lookup option for columns in MS Access tables. Instead create an intersection table which tells you the combinations of values from the two main tables that are allowed. So instead of having the multi-select Access column in tblUsers, you should have a separate table called tblUserAccess with two columns (UserID and CategoryID). The two columns together will form a composite Primary Key for this table, and individually they will be Foreign Keys to tblUsers and tblCategory respectively. (You should do the same kind of thing with tblType - remove the Categories column and set up a separate table called tblTypeCategories).
Coming to your query, are you expecting this to show you all the relevant Issues for a particular user? At the moment, it is not doing this. The reason it is prompting you for input is because it doesn't understand ([tblUsers].[Access]) - tblUsers is not referenced in your query, and the query has no way of knowing which particular user you're interested in.
With your new table in place (and populated with the relevant data) you should add tblUserAccess to the query, joining tblGMPIssues.Category to tblUserAccess.CategoryID. Take the ([tblUsers].[Access]) condition off the Category column. Add the UserID column to the grid and set the criteria to [Input UserID]. Now when you run the query it will ask you for a user ID, and it should hopefully show you all the Issues that the given user can access.
Good luck!
First, I suggest you normalize your data a bit:
You have a number of tables that are reference data (e.g. tables tblStatus, tblSeverity, tblLocation). You have a s a primary key a (system generated) ID. That is wrong! The primary key of these should be their data, i.e. status, severity, location.
I can't see what the relationships are between the data. It should be one-to-many, mandatory (i.e. one Status can occur in many tblGMPIssues and a status is mandatory).
Your table tblType is unclear to me but it contains the categories. I am not familiar with the '-' before Categories followed by a Categories.Value but I assume an occurrence of tblType can contain exactly one Categories.Value. If not, then you must decompose this table.
If a User has access to a number of Categories, then there must be a many-to-many relationship betwen Users and Categories. From this relationship you do your select query, but I don't see this relationship.
Use following query to get any of the Category IDs 1, 2, 3 or 4
Select * from tblGMPIssues where tblGMPIssues.Category in (Select UserAccess from tblUserAccess)
I still have many problems with your relational design, or actually the lack of a proper relational design. As an example, below is a diagram from my Access 2007 showing a part of your database with a proper design. Access automatically shows that "one" and "many" symbols (which I don't see in your diagrams). I also show the relationship dialog with the proper fields checked. Note that none of the keys of any table, except tblIssue, has a system generated primary key. They are all plain text whch allows better understanding when inspecting the data and, as said, the database automaticlly updates child tables when the primary key value of a parent table changes.
Note table tblCategoryType: it implements a many-to-many relation between categories and types, meaning a category can be of zero or more types and a type can be in zero or more categories. In addition to "update cascades", this table has the "delete cascades" checkbox checked so if a category is deleted, all its relations with types are deleted (not the types).

Custom Queries in Microsoft Access 2010

I am very new to using Access and databasing in general. I need to set up a database to manage car loans. I currently have the following:
A form which displays the information each individual customer
A button at the bottom of the form, titled "View Customer History"
A table with the records of all loans, sorted by car registration number
What I need to do is have access create a custom query which will display all the items from the table containing the loan records that have been rented by the customer that is being displayed in the form. I am aware that creating queries manually is an option but seems impractical due to the number of new customers loaning cars all the time.
I hope that the question made sense and appreciate any help I can get.
I would approach the task in this way:
Create two tables called "Customers" and "Loans"
"Customers" table should have unique records for each customer. One of the fields in this table will be titled "Name" and should obviously contain the names of the customers. Make this field the Primary Key. The other fields will contain other information related to the customer
"Loans" table will have a field called "Customer" which stores the names of the customer loaning out the car. Link this field to the Primary Key of the "Customers" table. The other fields will contain details relating to the loan
Now your form (name of form: "Information") is linked to the "Customers" table and shows all the information stored in the table. Name the field on the form containing the name of the customer as "CustomerName". At the bottom of the form you have a button for viewing customer history
Create the query: SELECT * FROM Loans WHERE Loans.[Customer] = Forms!Information!CustomerName;
Assign this query to the 'On Click' event of the button on the form
There are of course other ways of achieving the desired results, but the way described above is also sufficient.

Microsoft Access: Getting current record & creating child record before insert

In Access, I'd like to give the user a datasheet form to key in some data. This datasheet merges two tables together, a parent (Product) and a child (Book). I've linked them up using their IDs and they share a 1-to-1 relationship. However, while entering data, as long as I key in any Book data, the following error message shows up:
You cannot add or change a record because a related record is required in table Product.
And I am clueless as to what to do, so I thought that giving a administrator-only metadata to the Product table would help. When I set it to "Book" and create a new row in Product, a data macro will then programatically create a corresponding row with the same ID in the Book table. Does that sound feasible?
Anyway, I will need to retrieve the ID of the current record of the Book before insertion, so I wonder how'd I be able to do that.
Make sure the foreign key (=field with which the table is linked to its parent table) of the Book table is included in the underlying query.