The main entity in my database has about a hundred fields. I organized the fields between many tables and added a 1-to-1 relationship between the tables.
For data entry (and later data editing), I envision a "wizard" with a form for each table and a "Next" button to advance to the next screen/table. The primary key would be entered on the first screen and subsequently passed to all remaining screens.
I have heard a tab control with subforms might be the way to go.
What steps should I perform to create this wizard?
Note: Use the following schema as a simplified example of my database.
Sample Schema (can't upload images from work)
You can use a hidden TextField in the parent form which contains your primary ID.
For every of your subforms you just set in the properties that the subform is linked to the content of this textfield. This way you can get all your subforms synchronized.
Related
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).
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.
In my database is a Form based on a query which has a subdatasheet defined. When the Form is in DataSheet view, each record shows the plus sign which can be expanded to show related records according the subdatasheet defined on the source query. In other words, the Datasheet view automatically shows the Subdatasheet--as expected and as desired, so I know it can function like this.
I then created a new Form based on the same query as the existing, working Form. However, the new Datasheet view will not show the Subdatasheet... no plus sign, nothing. Next I created a test database with a couple related tables, and I also ensured that the tables have a Subdatasheet defined. If I open the tables directly I see the plus signs and Subdatasheet as expected. But once again if I define a form on those tables, it will not show the Subdatasheet when viewed in Datasheet mode. There is no separate setting for an Access Form to define the Subdatasheet, rather it can only inherit the Subdatasheet setting from its record source object (i.e. table or query).
Is there any way to force a Form (in Datasheet view) to show the Subdatasheet already defined on the record source object? Why might the new form function differently than the original even when it's based on the same query?
I'm using Access 2013 and database with 2007-2013 file format.
Subdatasheet view is only available in DataSheet view.
Also it is recommended to use Subdatasheet view for only reading and not editing as unexpected errors may result.
From Microsoft:
If you add subdatasheets to your tables, limit the use of these
subdatasheets to viewing, and not editing, important business data. If
you want to edit data in a table, we recommend that you use forms to
edit the data instead of subdatasheets, as data entry errors are more
likely to occur in datasheet view if users are not careful to scroll
to the correct cell. Also note that adding a subdatasheet to a large
table can adversely affect the performance of the table.
Microsoft Office Access automatically creates a subdatasheet when you
create a table that matches one of the following criteria:
The table is in a one-to-one relationship.
The table is the "one" side of a one-to-many relationship, where the
table's SubdatasheetName property is set to Auto.
A relationship is defined by matching the primary key and the foreign
key fields in the related tables.
You can also add a subdatasheet to any table, query, or form in a
database. In Datasheet view, a form can display only one subdatasheet
at a time.
We are rebuilding an asset database with Access 2013. We have 1 table with a Primary Key (Serial number of asset), and 22 other fields. We're designing a form to be used with the table so that we are not manually editing the table. The 'Status:' field explained later does not exist in the table; it is a user friendly way to show if the record exists or not.
The end goal is to have a form that will two cases. A user will enter a PK and hit the tab key. Then:
If the PK exists, it will pull the info from the other 22 fields and put them into the fields on the form (1:1) and update 'Status:' to 'Existing'.
If the PK does not exist, it will change the 'Status:' to 'New' and make all of the fields blank.
Most of the fields on the form will be Combo boxes. There will be a couple text fields and 1 date/time field.
Once a user is done with the form and has made any necessary changes, there will be a 'Save' button at the bottom that will write whatever is in the forms to the row indicated by the PK.
I have found partial solutions with the LostFocus() event in Access 2013 on the PK field of the form. I have little experience with MS Access, moderate experience with DBA, and no experience with VBA programming. I'm sure this solution can be done, my question is: can it be solved in a way other than hard coding the solutions? I also looked around for form building, but I couldn't find anything that worked how we need it so if there is a tool that can accomplish this, that is acceptable.
You might consider a form that contains a subform. Basically, you would design a form that has your PK input box and a subform. When the user hits tab (or a "Search" button), a query would run to search the table and display that record in the subform, or you could insert a new record if not. You may need to use a few queries and macros to link it all together, but it can be done code-free.
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.