Form Customization without VBA - ms-access

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.

Related

How to save row values from one field in subform to main form record? - Access

I have a parent form (frmGroupSession) that has a subform (SubFormParticipants) in datasheet view. The subform is based off a query that selects all participants ([CLIENT ID], [NAME], [ATTENDED]) that had attended a specific group [GroupID] on a specific date [GroupSessionDate]. The parent form saves to a table that logs group sessions (tblGroupSessionLog). I need to save the group's participants [CLIENT ID] to the record within tblGroupSessionLog
Basically, I need to pass data from the subform to the record within tblGroupSessionLog. I'm not sure what the most effective way to do this, if it's possible at all. Ideally, I would like to have each unique participant [CLIENT ID] stored in its own field within tblGroupSessionLog. If there were 20 participants in the subform then each row value from the first column/field [CLIENT ID] would be passed to the corresponding field within tblGroupSessionLog ([ClientID1] thru [ClientID20])
I am relatively new at this. Even asking the question was difficult.
I am not sure what else I can provide to help you wizards with the solve, but let me know and I will.
Thoughts? Ideas?
Access 101 : You have a many to many relationship You should look that term up but in short it means clients can belong to many groups and each group can have many clients. (so bang your data into a normalized structure similar to the following:
First tip make sure to add the relationships under database tools (you should look that up). Access needs to know how the tables are related to manage the keys behind the scenes and sometimes access makes better decisions about automatic form creating when it already knows the relationship structure. Once your data is properly structured access makes it easy to produce functional if much less than styling data entry forms which can also be used as even worse search forms. For instance Click on any table and hit create form on the ribbon and access will create the data entry form form you.
Basic Style tip 1: Always delete primary key fields like ClientID from the form. The field is still there in the form's record source being managed by access. Users almost never need to see any table keys. This gives you a basic data entry form which you can also use to scroll through any clients you have entered using the record selector circled at the bottom of the frmClients.
Play around with the record selector to see how it works. In particular go past the last record and you will find you can enter new clients and access will automatically give them a ClientID. You can also cycle through your Clients and update them using this form it just isn't stylish. In the same way we can make a form for the groups table.
You make a form for the frmGroupSessions table in the same manner as the others but add a step. Replace the text boxes holding ClientID and GroupID with human readable comboboxes. Here is a link to help with that: https://www.google.com/search?q=access+change+text+box+to+combo+box&oq=access+change+text+&aqs=chrome.0.0i457j0l2j69i57j0j0i22i30l2.7503j0j1&sourceid=chrome&ie=UTF-8#kpvalbx=_r0sFYJ7vBcfY5gLz2aTgBw15
Becomes:
At this point play around to learn. Use the Record Selector at the bottom of frmGroupSessions to add and modify data. Play with the Tables and see what happens. Start messing with the form properties in particular the default view. Soon you will have ideas about how the form could be better and you can start figuring out how to style them.

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).

How Do I Make a Subform Controlled by Report (Which is Controlled by a Query) Update After Records Are Added?

I recently took a duty position that requires me to track our administrative actions. Previously, the office had tracked them on an Excel spreadsheet, and the historical data was corrupted/missing. So I have built a database in Access 2010. I designed the database to display a main form that provides an overview of each action, but decided to require most of the data to be added or updated on specific data entry forms. My question relates to two subforms on the main form that I cannot get to update after data is entered into the tables. Here are specifics:
1) The main form is the case detail form, and each case has a unique case ID number that links most of the forms and tables.
2) The Case Detail Form has two subforms. One displays the names of the people involved in the case (this is the Subject Subform). The other displays the case history entries (this is the Case History Subform).
3) Both of the subforms are supposed to work the same way. Each is populated by a report which displays the information in its corresponding Subform. In turn, the reports underlying each Subform are based on a query that selects the records to display based in the case number.
4) New data for the subforms cannot be entered on the Case Details Form. Instead, the user can press a command button which launches a separate form that allows the user to enter either subject details or to enter a case history update. Once the user enters the data, he or she clicks A Save Record button, which saves the record and closes the form window. Everything seems to work fine up to this point.
5) However, I've now been working on this project for two weeks (as time permits), and I am still not able to make the two subforms update automatically. If it's a new case record, the user can make the Subforms update by using the navigation arrows to leave the main Case Details Form and then returning to it. If it's an established case record, a refresh button that I have added to the main Case Details form will cause the two subforms to update.
As I've tried to make this work, I've tried a number of approaches that I've found on various boards. Right now, I have:
A) The Subject data entry form has a Me.Requery statement in After Insert Event Procedure
B) The Subject data entry form has a SaveRecord and a CloseWindow command that are executed when the Save Record Button On Click event is triggered.
C) The main Case Detail Form has a executes a Me.Case_Subjects.Form.Requery when the GotFocus Event Procedure is executed.
I apologize for the lengthy question and explanation. I'm an Army officer and a little out of my depth with this. I would greatly appreciate any help anyone might be able to offer.
Best regards!
I'm not sure having understood everything but I try to give you some suggestions about what to try.
If I'm not wrong both form and subforms have the case ID as field so when you created the report you should have put them in "link" by the wizard (you can set it manually after but it's a bit more tricky).
Did you do this? This makes the form / subforms update when you navigate them.
Please note that there must be a relation between the underlaying tables to guarantee that the reports / forms moves together!
This applies to the query too, just remember to include the ID field int the queries.
If you don't want to see the ID (in case you use an autonumbering id) you can set it Not Visible.
In case you don't want to link the two tables with a relation there is another solution but it's a bit more tricky and, if it's not your case, I don't want to make confusion.
Let me know if you solved.
Bye
Firstly, the line Me.Requery should be on the After Update event, not the After Insert event. Secondly, you will then need to change Me.Requery to Me.[insertsubformname].Requery.
As the user above said, you will need to ensure that you have created your database relationships properly, however if you used the Insert Subform, it should've asked you what you wish to use as your link between the forms.

How safe using combobox to input foreign key

In a Related Tables, you need to enter a FK to link to the parent table.
You either key in the FG from memory !!!!!! or use help.
The standard procedure is to design the field as combo box AND use SQL to select the field that will help to input the ID of the parent table. So, if you want to input foreign key 3 , the combo box will display what 3 is then when you selected Access will insert 3 for you.
My question is since I can later on, edit the table and change the the value to another value, and mess the whole thing up!!! HOW can I lock my first choice so it will stay unedited ?
My second question is: Is this the only way to input the FK if you do not remember the exact ID number or there are thousands of records in the parent table.?
Re. #1
In Access 2010 you could use a trigger to check whether the value has been used in another table as a FK and not allow the change. In previous versions all you could do, would be to hide the navigation pane or make the table hidden.
Re. #2
You could use a listbox (basically the same idea as a combobox).
You could include the lookup table in the underlying query, but then there is more danger of the values getting changed, which is exactly what you were worried about in the first question.
Stick with the combobox.
You can create different versions of a form. One might have Allow Edits, No, another might be Data Entry, Yes, meaning that it can only be used to create new records.
However, suppose someone is creating a new record and they select the wrong FK by mistake. How can they correct this? You could use VBA to produce a confirmation dialog in the first instance, and perhaps an Undo button where VBA would deliberately perform the Undo. Access 2010 also has Data Macros (equivalent to triggers) that you might use to store the old and new values, and other information, when a user changes a FK value.
Access does not implement user-level security, so the user can still open and change data in the raw-data tables. You should, however, have enforced referential integrity on the table-join, so that a user cannot enter a FK that doesn't already exist as a PK in the related table.
In summary, you could add additional columns to the combobox to help the user select the correct item, and you might consider an additional confirmation dialog (a MsgBox) before a record is saved into the data-table. But you cannot prevent people from making mistakes. (Enforcing Referential Integrity will prevent nonsense data from being entered.)
Second question:
A combobox (or possibly a listbox) is the easiest way for users to enter a FK value, without relying on memory. An alternative would be to use a button (or other control and event) that opens a secondary form. This form might have some filtering features to help the user find the correct FK value. When this form is closed you would then need to write some code to update the relevant control on the main form.