Self Containing Form for Heirarchical Data - ms-access

I'm attempting to store legislation inside an access database. Due to the inconsistent numbering and heading/subheading use, I was intending on storing the data in a flat table, with a "parent" column storing the ID to the heading, or the subheading, or the section text etc etc etc.
So - for instance
ID Section Parent Description
0 1 Purposes of the act
1 a 0 The purpose of this act is to:
2 i 1 Manage data efficiently
3 ii 1 Test access
4 b 0 More data goes here
would represent the data
1 - Purposes of the act
a - The purpose of this act is to
i - Manage Data Efficiently
ii - Test Access
b - More Data goes here
My issue is in using forms to effectively edit the data. The best approach (from what I see) would be to embed a form within itself as a subform - which is evidently not allowed. My intention was to have 2 new buttons - one for new item, one for new child. The latter which would create a child item and show it (and the other child items) in the subform.
Is there another way to do this?

I'd have a continuous form displaying the whole law/by-law (you should be able to format it for display in the source query); however, each section could be double-clicked on to open another form (perhaps modal) to edit the section.
Logically, you'd have controls for inserting, deleting, indenting and outdenting particular sections.
I suspect you will also want to include an "order" column for each section. Suppose you want to change the order of 1.a.i and 1.a.ii. You can't change the ID column, because it's probably an Auto-Number.
Of course, an obvious question is why not just store the law/by-law in MS Word and store references to it's location in the DB

Related

Input multiple objects of a class in a single HTML or Flask form

For the sake of simplicity, say I want to build a shopping list using Flask using a table in a format that looks like this:
Name
Cost
Amount
Sell-By
Apples
1
5
2022-07-18
Bananas
0.7
7
2022-07-20
I want the shopping list page to initially look like this, with a user able to add any number of items before submission
Name
Cost
Amount
Sell-By
(User input)
(User input)
(User input)
(User input)
When submitted each line should be able to be initiated as a SQLAlchemy object and saved into a database.
I've tried using FieldList and FormField from WTForms but can't quite get the hang of it (and don't really feel it's appropriate in this situation anyway). I don't usually struggle with forms, but having multiple instances of the same form AND trying to put that in a dynamically generated table is really tripping me up, so any pointers are welcome.
The content/size of a shopping list should be adjustable during writing.
Therefore i suggest you take a look at JavaScript and add a simple Button that generates a new row´each time you click it. Each row then contains the needed String or Number fields.
If you send the form you can simply move the entries to your Database

Passing Variables Between Forms

Forgive me if this has already been asked- I can’t seem to find a well written answer.
I am developing a small application for personal use.
Essentially what I have is two forms. Form 1 is a master view of all my contacts listed on a data grid view. Form 2 will be loaded on the cell/row double click of a particular record in order to edit it’s details.
My question is, what is the best practice/method for achieving this? I have seen many different methods.
Should I:
Pass only the primary key of the selected row then populate the fields on form 2 load
Pass all fields as a variable within a class then populate form 2 from that
Maybe I’m headed in the complete wrong direction though.
I have tried both ways, but wondering what the best method is for scalability.
My personal preference would be to pass a datarow into the opening argument of the form (rather than the PK / all the variables). You can then use the datarow inside your Form2 to bind to your controls or set their values, whichever you think is appropriate.
There are some useful examples on working with a datarow if you're unsure, alternatively you can also check out Microsoft Docs.
Public Sub New(ByVal row As DataRow)
InitializeComponent()
' your code for working with row here
End Sub
Edit:
In terms of "Binding" vs "Setting", you can either have your controls linked to your data to be two way (as you edit the data in a control at run time you alter the data in your database) or you can just set the values of the controls.
E.G. TextBox1.Text = row(0)("ColumnName")
You can find more on data binding on the Microsoft Docs page

Is it bad practice, security-wise, if user could know the primary key id of items

I am populating a page with a list of items from DB (lets say main.htm - each item has a link, and opening a link will display the content of the item.
I am using ajax to open the items. For performance reasons, I have added data attribute of their ID to each item in main.htm. so if main.htm has 15 items listed, each item will have a data-id, e.g. item 1 has data-id =1, item 2 has data-id=2
and data-id will correspond to the ID column (primary key) in the Database.
Is this a bad practice, security-wise? if yes, why?
Or is it better practice to encrypt the numbers and instead of id, assign the encrypted id, such as xY4lf3K which would decrypt to 1000 in DB
This should not be an insecure way to go, just as long as you keep in mind to:
ALWAYS escape & validate user inputs (remember, a $_GET param is a user input, not only $_POST);
If the resource identified by the ID is for a specific user, check if that is the user accessing it.
Otherwise, no problems there.

Infopath Linked Fields

Pretty new to Infopath here and I can't seem to google this right so i'm going straight to my last option!
I'm building a form in which a Dropdown list needs to change dependant on the value of another dropdown list
So If X = 1, Then Y = 3 etc.
I'm just not aware of the functionality of Infopath and how I can get something like this working.
Thanks.
What you are looking for can be described at the following post:
Auto-populating an Infopath form after selecting a drop down
Essentially you will be using the rules manager to indicate that when a field equals something it will populate another field with data related to it. Think of it as more complex vlookup. Additionally, the verbage you would want to use to google more on the subject would be along the lines of "infopath auto-populate field based on another fields value".

MS Access Controlling Copy/Paste of Data from Continuous Form

I have a user that is dealing with an Access Database continuous forms page where they can perform a bunch of filtering and data entry.
Occasionally the user wants to be able to select a few rows from this form and paste them directly into an email. Outlook formats the data into a table pretty nicely on its own but the problem we're having is that dropdown controls from the header are included in the pasted data as you can see below:
Employee_Absences
drpEmployee drpOrgDescrip lstTimeCode txtToDate txtFromDate chkShowExcused DESCR AbsenceDate Hours Excused_Hours Time Code employee_lookup.ORG_DESCRIP ImportedDate
6/2/2009 1/1/2009 0 Bob 1/4/2009 4 0 VAC Medical 5/7/2009 4:51:31 PM
6/2/2009 1/1/2009 0 Bill 1/4/2009 6 0 VAC Medical 5/7/2009 4:51:31 PM
6/2/2009 1/1/2009 0 Betty 1/4/2009 4 0 VAC Medical 5/7/2009 4:51:31 PM
6/2/2009 1/1/2009 0 Beth 1/5/2009 2 0 VAC Gamers 5/7/2009 4:51:31 PM
The user doesn't want to bother with deleting and reordering columns every time they want to include a couple rows in an email and it would be fairly unfriendly to force them into a separate report or datasheet just to get two or three rows. I've tried messing with the order of the parameters in the query that is populating the form but this doesn't help at all.
Is there some sort of Copy-to-Clipboard event that I can hook into and do some magic to the data rows? Any other suggestions?
This is surely a layout problem on the form. Selecting rows of a continuous form should not copy the data from controls in the form header.
Perhaps I've misunderstood the problem?
It certainly is possible to put data on the clipboard. See this page:
Copy variables/control contents to memory
But for pasting into an email, you'd need plain text and the email would need to be displayed in a fixed-width font. Unless you want to write HTML, there is no easy way to format a table that will paste into a non-plain-text email. If they are sending in HTML (which they oughtn't be), an HTML table will work. If they are using RTF (and they oughtn't be), I don't know what happens if you paste HTML.
Try to figure out why the form header control is getting copied. My bet is that the user is not defining the initial selection correctly, and you teach them to do that (or engineer the subform to prevent it), you won't have to program anything -- which is the whole beauty of Access.
On another note, I don't believe in allowing edits in continuous or datasheet forms because if you need dynamic combo boxes and the like for data validation, it can lead to all sorts of problems. Instead, I use continuous and datasheet forms as lists and have a detail subform bound to the PK of the continuous/datasheet form so that when you select a record in the continuous/datasheet form, the data will appear in the editable detail subform.
I have just had too many problems with editing continuous and datasheet forms and that's why I've done that. The only exception I make for that is in an invoice-type form, where there is no good way to do it otherwise.