Access continuous subform with checkboxes to store ticked values with mainforms id - ms-access

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.

Related

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.

Question on bound/unbound forms in 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.

How to edit an existing record and not create a new one when using subforms in Access?

I have an access database that holds medical information. It holds quite a bit of information so i have grouped like fields together into individual tables and linked them using a common primary key. I have created a tab style form with subforms on each tab.
Some of these subforms contain fields from only one table, however there are a few subforms where i have included fields from more than one table.
For example, i have a table that holds blood transfusion data and a table that holds patient characteristics. Some Fields from the blood transfusion table and patient characteristics table are in the same subform, but I also have fields from both these tables in other subforms.
When i try to insert data into the sub-forms with fields from multiple tables i get the following errors..
update or cancelupdate without addnew or edit
and
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.
From researching the problem i gather this is because access is trying to create a new record for both tables, but if a record has already been created with that primary key (from inserting data into a previous subform) it won't edit the existing record.
Does anyone know how to get access to edit the existing record in this instance instead of trying to add a new record? I have basic skills in VBA but this is a bit past my level of experience.
Any suggestions would be greatly appreciated.
I used have a whole long response about split forms instead but I was having a horrible time getting it to work. So here is my new and improved answer for using subforms.
Here is a link with sub form info if you want to brush up for your purposes https://support.office.com/en-us/article/Create-a-form-that-contains-a-subform-a-one-to-many-form-ddf3822f-8aba-49cb-831a-1e74d6f5f06b
Step 1
Make sure your main form is bound to the right table.
For my purposes I used a single combo box on my main form to search with. Make sure all the field parameters on your combo box are correct. This includes making sure the Row Source is correct and that you DO NOT have a control source entered.
Step 2
Don't press enter after making a selection in the combo box. To prevent people from hitting enter I created a dummy button at the bottom that says "Save and Refresh" but all it does it create a message window that pops up with "Save Successful". I find hitting enter creates the first error you keep getting. I'm not sure how to address this in a more sophisticated way yet.
Anything else that comes up I will add later.

Checkbox per row in multi user access database

I have the following situation:
I have a many to many relationship.
For example an Employee Table, an Course table, and an relation-table inbetween.
Now I want that the user can select out of the course table his courses in a dialog form.
That means that the underlying table for my continous form inside the dialog is the course table.
I want a checkbox in every row which indicates if the course is selected or not.
As I read it is not possible, to add an unbound checkbox, because they are just copies, and a select click would select all of them.
The solution would be to add an yes/no field to the underlying table courses.
But here I have the problem as I understand the matter, because I have several users using the database at the same time, that the underlying table will be updated if I click one checkbox and this update will select the value for all users which are using the dialog form concurrently, what I dont want.
So my question is, is there another solution to get a working checkbox per row in a multi user access database.
There are two solutions which I could imagine:
1) The underlying table will be the relation table and in this every possible combination between employee and course will be saved together with a yes/no field. (but that would be from a data view point quite horrible)
2) If the changes to a checkbox would not be directly written back to the database table, I could discard them on saving and manually insert the relation records in the relation table. (Is that possible?)
Thanks for any solution proposals
I see two good approaches:
1) This assumes that your database is split in a network backend + each user has a local frontend. This is the recommended setup for multi-user.
The frontend has a local table with Course_ID and a yes/no column.
A join of this local table with the Course table is the recordsource for your continuous form.
On loading, you copy the course ids into the local table, and set the existing relations to True.
On saving, you update the relation table.
2) Use a ListView control instead of a continuous form. It has inbuilt checkboxes. Loading and saving is done with a VBA loop.
Based on your description I assume your form has a LEFT/RIGHT JOIN in its data source where some ID field is null if the specific Course/Employee combination does not exists in your relation table. Let's call it LinkID. Then your checkbox should be something like =NOT ISNULL(LinkID). While you will not be able to use the OnClick event for the user to check/uncheck this way, you can use the onMouseDown event to see if the user clicked the checkbox and take action accordingly.
That way you don't need an "all combinations" relations table, no temporary table and no Yes/No field. If a record with the Course/Employee combination exists the box is checked, if it does not exists, it is not checked. Adding and removing courses is done by adding and deleting records from the relation table.
Have a look at this How to use unbound checkbox in a Continuous Subform - MS Access. A class that binds an unbound checkbox. Better than listbox, because you have a form with all its benefits (sort, filter, edit, append).

Subforms integration not working seamlessly in Ms Access 2010

I have a form in MS Access 2010 with two sub forms in it. I've defined one-to-one relationship with the tables behind the forms. Both the sub-forms should be used to create a record in corresponding tables and then update the foreign key in the parent form. But when I fill the sub-form first, an entry is created in the corresponding table but the foreign key doesn't get updated. Shouldn't this happen automatically? Or should I add code for updating parent form's field?
Also when I start filling the main form first and then jump to any of the sub-form, I get the following error message:
"You must enter a value in the 'Activations.dbBoxID' field" (Activations is the main form here and dbBoxID is the foreign key field.)
Another issue is that I don't want sub-forms to update the corresponding tables until an entry in main table is also created (i.e. all required fields in main form are also filled).
I am new to MS Access. Any help would be really appreciated!
The concept you are missing here, and what's not being explained to you is that when you build a master to child relationship in access, you can model these relationships with forms and a sub form, but you base the forms on the actual tables and not queries that are an result of joining those tables together.
In other words, your master form should be based on the main or parent table. DO NOT join in the child table. I'm going to repeat this again: do not join in the child table.
So you can base the master or main form on a query, but when you do so, do not join in the child table in that query. In fact, in most cases there is really no advantage to using and basing a form on a query anyway. Simply create the form, and base it on the table.
The SAME ADVICE applies for the child form. You base the child form on the child table. You DO NOT use a query with a join.
The reason why you're getting error messages is because you have a query for the main form that is based on two tables. With an enforced relationship, when your focus switches from the main form to the child form, a record save of the main form occurs, and thus you're getting the error message.
So your error and problem is due to you basing a form on a query that is a join of two tables when it is not needed in this case.
A form with subforms works better if the data in the parent form are entered first. Then the subforms can be joined on the parent_key to foreign_key in each table without any code.
If you want to let users enter records in subforms first, don't update them until the parent form is completed/saved, you're going to need to do some coding. Not sure why you need/want to do that?
A client form with bills and payments subforms, for example you would enter enough client data to create a record. Then bills and/or payments can then be entered.