Question on bound/unbound forms in MS Access - ms-access

I want to create a form populated with data from two tables, say table A and table B. The data from table A refers to a single row in A but the data that I have to retrieve from B is several rows long. I succeeded in doing so by setting up an unbound form and running a SQL JOIN query to fetch the appropriate data in VBA.
Then with VBA I was able to distinguish the data from the multiple rows in B.
Is it possible to achieve the same with a bound form so that I save myself from excessive coding? I can't figure out a way to populate my controls in the form with data from the rows in B.

If I understand you correctly, your two tables are related, that is, you search in B based on a value on A. If that's the case, the usual solution in access is to use a main form and a subform inside the main form. Then you link the two. When you insert the subform, a wizard will appear asking for the relation. You set up the columns that are common in the two tables, and everything works, usually. You can anyway add the relation later.

Related

Subtables in MS Access

I am working on a database that has one main table with the entry rows having an individual table for calculations.
So I have about 9 tables that have calculations /values in that are associated with an individual indicator field entry in my main table. I would like to link the calculation tables to the individual entry.
The subdatasheet allows me to do this. However, it populates all the entries with the same table which I do not want as one calculation table is only associated to one entry.
I can’t create one table for all calculations as they have different types of data and are calculated differently so I can’t link with regards to relationships.
The only solution I can think of is by populating a new field called “results calculations” and populate it with the title of the calculation table associated to the individual entry.
Is there another way I would love all the data to be as accessible in one table as simplified as possible.
(I am new to MS Access so any advice will be appreciated.)
The result of using subdatasheet
What I need to link to each indicator

How to Design Query for Two Tables Not Directly Related

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.

How do I create a form which will save similar data across all tables?

I know that you can save one form data to a specific table but I'm not sure how to do it for multiple tables. I've enforced referential integrity in my relationships but nothing happened.
Well, you likely need to add a bit more information.
As a “general” rule, a form is bound to a table. It lets you edit, or add records to that table.
However, given that Access allows you to deal with relational data, then to save records to “more” than one table, those tables will follow the “relations” you setup between those tables.
So for example, if you have say an invoice form, then the top part of the “main” form could (would) be bound to the table “invoices”. And for each invoice, you have “detail” lines. That is a table (likely called table: InvoiceDetails).
So your result is a form like this:
So you never really make “one” form write to multiple tables, but you most certainly will build a form and add additional forms to that one form. These “additional” forms are what we call “sub forms” in Access.
The “base” concept here is that the form will “appear” to update multiple tables, but the form is in fact made up of MORE than one form. These additional “sub forms” are how you edit (and add) related data tables in Access.
In above, the top part (our main form) is bound to table “invoices”, and each line of invoice detail (table invoiceDetails) is a sub form below. And access forms can display one record, or “many” records. When you need to edit (or add) multiple records to a table, then you create a “multiple items” form (let the wizard create the form for you).
Each form is as a general rule “bound” to one table, but by cobbling together multiple forms into “one” form (as related sub forms), you achieve the goal of editing data in multiple tables.
So above is just really a regular plane jane Access form. However the "repeating" details part is another form (a sub form, and is a multiple items form).

How make appears a field from the field list automatically?

I just started to use Access with vba. I have table with roles, years and its workload of each role in this specific year. Each record in the table is IDRole, IDYear,Workload (number).
I display the table in a form doing a crosstab table where the years are in the columns and the roles in the rows. The number of years can increase.
My problem is when I add new years and display in the columns, it doesn't appear in the form so I have to select from the field list manually but I would like to know if there is any way in VBA that when the form is load, automatically appears the new columns (years).
I misunderstood your situation. Your form's crosstab data source is actually a table instead of a query. And as you add columns to that table, you want the new columns to automatically appear in the form when you next open the form.
In that case, use the approach described below, but where I selected a query (Query.qryFoo2) in the Source Object dropdown, choose your table ... Table.YourTableName ... in that dropdown.
The last 2 paragraphs below apply whether your data source is a table or query.
If you have your crosstab query saved as a named query, you can use it as the Source Object for a subform control.
Then when you switch from Design to Form View, the query results will be displayed in Datasheet View within the subform control.
As the number of columns changes over time, that Datasheet View can "automagically adapt" to display them ... the same as if you opened the named query directly in Datasheet View.
As far as I'm aware, there is no other reasonably simple way to accomplish what you want. If this suggestion is not suitable, you can explore programmatically adding bound data controls to your existing form after examining the set of fields the query currently returns. But that is way too much effort IMO.
I have exactly the same issue, I have a form which I use to show a Query, And I can't anticipate the number of columns from the query.
I found the same topic on other pages, and for the moment the only way I found is to build an excel file based on the query.
Another way also is maybe to directly open the crossTab query using vba.

Access continuous subform with checkboxes to store ticked values with mainforms id

I am a newbie to MS Access and trying make a productivity tracking program for where I work.
I have a main form that's bound to multiple subforms with ID and I need to add one more subform.
That subform is going to fetch all data from Personnel table in continuous form view, and I would like to add one checkbox and two more fields to each row in continuous form. The ticked rows needs to be stored in a different table.
Is there a way to do this?
You'll have to make the new table
Then make a query which relates the new table to the old and returns all of the values you want edited or displayed in your subform.
Make the subform based on this new query, since it is only 2 tables it should be editable if the join isn't to complicated.
Then using the Locked and Enabled Properties of the controls on your subform you can change what is editable and what isn't.
I will say that if this is a one to one relation between the new table and the eixisting table it would be much easier to just add the fields and deal with security/data reporting concerns elsewhere.
Attempt to clarify more
I am assuming your Personnel Table has a foreign key to the main table ID and a personnelID of its own. To have more fields that correspond to records in the Personnel table you need to create another table, we will call it CheckBoxes. Checkboxes needs to have a foreign key to the personnelID and then whatever fields and check boxes you require.
Then you need to make a Query that pulls from Personnel and CheckBoxes and joins them on the foreign key you have relating the two tables. Then make your continuous subform based on the query rather than a table.
Access makes the query creation really easy and this relaition should be simple enough to be able to edit through the query.
Again I would consider adding these fields to the personnel table rather than making your database more confusing than it has to be but that is up to you the designer.