MS Access Filter Child Table by Record Chose on Form - forms

I'm trying to create a simple 2 table database - table 1 holds ClientInfo and table 2 has ClientVisits - Relationship is on ClientInfo.ID->ClientVisits.ClientID. Then I have a form created thus for viewing the ClientInfo plus a child(sub?)table which SHOULD show all the records from ClientVisits where my Form ClientID = ClientVisits.ClientID.
Here is my form
Here is the child table with fields shown
Relationships
So I already have one record in ClientVisits for the currently chosen ClientID form record. But it doesn't show in my Table.ClientVisits. Other than the relationship I don't have any other link between the ClientID and the ClientVisits.ClientID field.
If I need to post further info please let me know, trying to describe this as well as I can - sorry if it's not making sense. Thanks.

You have to link both tables in your form.
In my example, main data of my form is a table called CLIENTES, where it shows all the information about a cliente. It would be exactly the same as your table ClientDetails. In this table, primary key is a field called DNI (it would be the equivalent of your ID field)
I got a second table called CONSULTAS MÉDICAS. This table is just a list of how many times this client comes to see us. It would be the same as your secondary table CLIENT VISITS. In this table, I got a field called PACIENTE, linked to my table CLIENTES. Let me show you.
Ok, now my form is done based on the data of my table CLIENTES, but I got a subform control, where I have linked the table CONSULTAS MÉDICAS
To make this work is pretty easy. Not filters or queries. Just linked child and master fields. To do this, you have to select properties of your subform control, and then go to DATA TAB
Just choose as main field your ID field from table CLIENT DETAILS and link it to child field CLIENT ID from table CLIENT VISITS
That should work for you.

Related

Nest TypeORM Postgres update user's column('number of posts') based on the userId in the Posts Table

I'm wondering if it's possible to auto update the User's column('number of posts') if the Posts table updates. The Post entity has a ManyToOne relation with User('userId'). Is there a way to make the User Table "listen" to the Post Table and automatically updates the number of post column, or i need to write it in the post service create function to do so. I'm new to sql so i'm just trying new stuff. I'm using NestJS,typeORM, Postgres and Graphql
#Kendle's answer does work and has the advantage of pushing the computation and complexity down onto your DB server. Alternatively, you can keep that logic in the application by leveraging TypeORM's Subscribers functionality. Documentation can be found here.
In your specific use case, you could register a subscriber for your Post entity implementing afterInsert and afterRemove (or afterSoftRemove if you soft delete posts) to increment and the decrement the counter respectively.
You don't want to duplicate that data. That's the whole idea of a relational database that different data is kept in different tables.
You can create a view if you want to avoid typing a query with a JOIN each time.
For example you might create the view below:
CREATE VIEW userPosts AS
SELECT
user.id,
user.name,
COUNT(posts.id)
FROM users
LEFT JOIN posts ON user.id = posts.user_id
ORDER BY user.id;
Once you have created the view your can query it as if it were a table.
SELECT * FROM userDate WHERE id = '0001';
Of course I don't have your table definitions and data so you will need to adapt this code to your tables.

Inputting data from a form into a junction table Microsoft Access

In access I want a single form which can input data into a junction table. The relationships are as follows.
One table has plant names and basic information on the plants, another table has soil moisture content and another table has county names in which certain plants may be found. One plant may be found in many counties and many plants may be found in one county. Same goes for moisture. Thus, this database needs to many to many relationships. How can I make a form which takes a plantID as well as the counties and moistures of that plant and forms an entry in the junction table? Am I approaching this problem in an appropriate way?
Assuming that you only need to add records to the junction table from this form, build a form bound to the junction table.
If you use the wizard, your new form should list each field as a textbox.
For each field that is a foreign key, change the textbox to a combobox. Use the row source property to pull the information from that field's devoted table where the PK resides.
So for example, MoistureID will become a combobox whose row source would be:
SELECT MoistureID, Moisture
FROM Moisture;
The ID field will then be the output of the combobox but will display the Moisture field when the list opens. You can hide the ID field from the user by changing the "column width" property to 0";1" but make sure the "column count" property = 2.
Then you can change the form's data entry property to "yes" to hide the existing junction records from the view of the form.
In form view, choose your plant ID and other selections and once you tab past the end of the form's tab order, your junction record should append to the junction table and the form's controls should clear.
If you need to add records to other tables from this form then you will need to build an unbound form and handle the appends using macros or VBA.

Can't add or edit records in form after updating relationship MS Access

Previously I had a Payment table's Form and a Current Tenant's Table's form. The Payment table was related with the Current Tenant's email address.
Later I realized the Payment table needed to include details of old tenants. So i created an append query to create a table containing details of all the tenants. And I changed the relationship so that the payment table is related to the email address from all tenant's table. Now using the Form, if i try to add a record using the form, it shows "You can't go to the specified record" and if i try to edit the records, it displays "The record set is not updateable". But i can add and edit record using the table. This problem only exists when i try to include the "Name of Tenant", "Tenant's Contact Information" or any other field from the "All Tenant's Table" in the form. How can i fix this?
Note: The email address in All tenant's contains duplicate records due to different Check out and Check in date. Except those, all other records are same.
When you join multiple tables in Access in order to allow updates across both tables, you need to join using a Primary Key.
Here is a great reference on the subject of Primary Keys.
Be sure that your "Current Tenants" table uses email address as a primary key, and then join it to the "Payment Table". The Payment table should also have a primary key (likely an 'auto number' field).
Ok, i found a way to solve the problem... I edited the relationship so that the All tenant's table is joined with Current tenant's table by Type 3 relationship. And Then joined the All tenant's table with the Payment table... It then solved the problem...

Duplicating MS Access main form record while keeping the parent-child link in the subform

I have a Monthly Reports entry form (data source: MonthlyReports table) with a Project Info subform (data source: Projects table) linked on ProjectID field. ProjectID is a PK in the Projects table and a FK in the MonthlyReports table.
I am trying to use the Duplicate Record button to duplicate the record in the main Monthly Reports form, edit the duplicated record and save it as a new record/monthly report for the same project. I would like to keep the Project Info (or ProjectID link) in the new record after duplicating. When I duplicate the record, it creates a new Monthly Report record with a unique number, but it does not keep the ProjectID foreign key, thus creating an unrelated record without the ProjectID foreign key. How can I modify the macro or add a VB code on click of the Duplicate Record button to keep the Parent-Child field link?
Thank you.
Short answer, If I understand what you're asking, is no.
When you have a relationship between a master and child table, it is a one (Master record) to many (child records) relationship. A child cannot have more than one parent. Even if you haven't defined this relationship in the database, when you link a subform to a master form by a field, that one-to-many is (properly) assumed.
What you would need to do is have the macro, subsequent to creating a new master record, create a new child record then copy the fields of the existing child record to the new record. Finally, you will need to set the value of the new child record field [ProjectID] to be the value of the newly created master record. Now you have the complete duplicate.

Ghost change my data after close form

I have a little databes in access. I make a few forms with sub forms and drop list(by query):
Steps of my creating form:
make form from table
delete all not PK or FK text box
create comboBox with store value to text box what I choase
create subForm and set Link Master Fields and child fields
design view:
This is form for table Task task have Fk: Project, peson etc. DropLists are connected tu subform for changing FK like project, person etc. So when I work i select in droplists what i want add to database and work with subForm. When I close this form, the first row in table change FK to last configuration on droplists.. Pleas how can I fix it?
It is quite possible to use a main form for selecting and updating subform records, but in this case it should not be a bound form.
To set up, for want of a better word, a linking form, unbind the main form, that is remove the record source and ensure the dropdowns (comboboxes) do not have control sources. I suggest you rename the dropdowns to cbo, to indicate that they are controls, not fields. The hidden controls should not be needed.
The value of a combobox is the value of the bound column. The Key or FK is the first item in your SELECT statement and the bound column is 1 (one) so the relevant Key or FK is the value of each comboboxe. You can set the link master fields to the names of controls so the Link Master Fields should be cbo_id_projekt;cbo_id_os_udaje;cbo_id_komponent;cbo_id_uloha.
As an aside, I generally avoid underscores, but each to their own.