Dynamic Forms, VBA, and adding fields to a form from a user experience
Hello all,
I have been doing some searches to see if there were already a solution out there but cant find one to fit my needs.
What I am trying to build is dynamic form that allows the user to add/remove fields as needed. To describe what the page is. Its an employee database that tracks all employee data (employee table) as well as certain training/thresholds they reach. The issue is that as this is being used more by my company different divisions have different training requirements. So I have two options 1) to be the person that has to adjust and customize the form for each division/section that has different requirements. 2) Develop a way for the users to be able to add columns (I have already developed a function that will allow a user to add columns to the backend without having to actually use the back end with an Alter Table function) that will then appear on the form.
Note: This is the code I worked out to add user selected columns to a table for the first part of this function.
Code:
Dim dbs As Database
Dim Ctype As String
Dim Cname As String
Ctype = Me.ColumnType
Cname = Me.Cname
On Error GoTo Err
CurrentDb.Execute "ALTER TABLE PipelineTest ADD COLUMN " & Cname & " " & Ctype & ";"
Err:
MsgBox Err.Description
Where I am stuck is being able to add an editable field to the form as needed by the users without me having to code it in. I can get a list function to grab all and even new fields to display the data. But then being able to click on that particular area to add a date into the box. With the current hard coded function the overall form is a repeating form that displays the records with filters on top and details on the employee below with the data needed for the processing in the form function that allows them to edit each field to add dates, select yes/no, or enter text as needed (similar to a spreadsheet).
I have considered doing a split form/Subform with the data showing from a query or table but the query doesnt update to show the new columns. In the sub form the fields are locked based on what was in the fields when the form was saved. I also am trying to make sure to have the maximum flexibility with fewer forms if able.
Is it even possible to use VBA to add new fields into a form programmatically that is virtually invisible to the users? If so any suggestions for coding to do this?
Update: One thing I am considering is using like 20 unbound fields on the form, a user selected form that allows them to "turn on/Turn off" fields and using that table based on the user selections to connect the unbound fields to the data via VBA.
Also sorry if this doesnt quite make sense.
The tables are already designed in this direction
Quote:
Originally Posted by
xps350
Yes, a bit.
I still believe the solution should be in your data model. You could make tables like
- employee
- division
- training
Also several tables to store related data, like
- employee-division (who works where)
- division-training (what is required where)
- employee-training (who did what)
Yeah I already have the tables. Thats not the issue. The issue is having a form/Table that can be changed dynamicly by the user without having to edit the back-end and/or edit the form. The users are not access smart and I dont want them editing or modifying the forms. I do however need a solution that allows them to add a column to a table (already solved) that then appears in a form for them to add/edit data in. I already have the form. I already have the tables that are connected correctly and even the queries. I can make it work if I make the data into a list box, however the list box does not allow them to edit the data in a particular section without having either another pop up or placing all the data sets in a different section of the form. Having the data sets show up as a query (to use the linked data of employee -> training) doesnt solve the problem either.
I think I have come to a solution of placing 20 un-bound text boxes on the form that can be dynamicly changed through a user preferences form and table. This allows the user to select up to 20 columns they want to see/edit from the form. Then using VBA to reference the table that the userpreferences are stored in to change the controls of the un-bound text boxes on the training form.
So basicly on load
dlookup- user preferences table and filter to username this pulls the
yes/no for display or do not (no sets size of field to 0)
user selected fields they want displayed in what order through a combo-box that pulls the column headings from the training table.
VBA to change the settings on the training forms to match the user selected preferences.
This way a user can de-select data they no longer need, add new column(s) if needed, and have it displayed without any coding from me allowing me to have one "developer view" that I push out to all the divisions without having to spend hours customizing it to each division/program.
Once I have it all coded and put together/running I will post my table structure and coding and examples of the forms to demonstrate. I came here first to see if anyone had any simpler solutions through just VBA vs where I think it needs to go.
Yes...I know. Access is not normally used for this. Right now my company is using this solution due to the cost effectiveness (they already have the different functions we are using) and it only costs them to pay my hours spent. I am pushing for an actual budget and team (as it gets bigger and more complicated) to move this out of access/sharepointlists to SQL/Python front end. Until then I am still supporting multiple divisions and data part time and need to develop in a way that is most efficient for my time. Rather than spending hours customizing I can place the customization part on the users if designed right. That function can then be carried into the actual project that it needs to move to in the future.