Tracking Form Updates with VBA - ms-access

I've been working on a database for a little while here, and while I'm still kinda new to MS Access, I do know how to code some basic things. Nevertheless, what I'm trying to do isn't so much needed as it is something that I would like to add in just to make the database easier to use.
What I've got right now is a form that will allow a user to put in first name, last name (UserID will concatenate both last and first names, respectively) and the password, but here's the thing: If a user opts to close out of the form before saving, I've successfully implemented the On Unload event to ask the user if they'd like to save said information before closing the program. The issue is, it does that ANY TIME the form closes. Is there some way I can have the Save Record button be tracked, or be able to track any sort of updates on the form itself?

I can think of two potential solutions (not in any order of preference):
If the form is as simple as you say (just 4 or 5 controls) then when it loads save the information in some "state" in your form. Then, in the Form_Unload event, check to see if the form content is different from the one in your state. If it is, prompt the user if they want to save the data, otherwise carry on and do nothing since there have been no changes. Of course, if the user at any time presses the "Save Record" button, then you'll also need to update your state to contain the latest saved information.
Another way is to keep a clean/dirty flag for each control that you are interested in (username control, password control, etc.) and that the user can type data into. Most/All controls have an event to track if the data inside them has changed. So use that event and set the dirty flag to True if any edits happen in each control. When the user presses the "Save Record" button, then the flags should become clean, since the information has been saved and is up-to-date. Again, in the Form_Unload event, check the flags and if any are dirty then prompt the user to save, otherwise carry on and do nothing.

Related

MS Access: Allow user to update data from form, but not from table

I want to allow user to update data from form, but not from direct table. I added Before Change event on table, and raising error if the user group is 'basic'. This is working as expected if I enter data in table. But, it is also raising error even if saving data from form. Can anyone help me to resolve this issue?
Thanks in advance!
In general the way to deal with permissions in Access is to only ever show your users the forms; they should never directly interact with a table or query. So instead of adding Before Change code to your table, you instead want to hide the table.
The things you need are in the Current Database section of the Access options. For this example I'll assume you just have the one form, but the same applies if you have many forms and a "Home" form.
Use the "Display Form" dropdown to select the form you want the user to see when they open the application.
Un-check "Use Access Special Keys" to prevent keyboard shortcuts showing objects you don't want shown.
Un-check "Display Navigation Pane" to hide the object list.
Un-check "Allow Full Menus" to prevent users from creating new objects (or use other database development functions)
With this done, the user will see only the form interface you selected and the basic data entry toolbar.
Note that when you want to make changes to the file as a developer you must hold down Shift when opening the application, which will display the navigation pane etc. Of course, any user who knows about the Shift override could do the same. Which is why distributing in a compiled accde, which cannot be unlocked, is a good idea. But you need to set up the application using the above options before that matters.

MS Access Letter Generator

I have a number of letter templates which I want to populate with data from my MS Access database and am unsure how to go about it.
The way I want it to work is as follows:
User is viewing a record within MS Access;
User presses "Generate Letter" button;
Choice of .doc/.docx templates (which I already have) appears;
User selects template and presses 'OK';
Letter is generated and populated with data from active record;
Once user is finished with letter, pressing 'Save' will attach it to active record;
(Ideally) any generated letters will appear within the attachments of each record (I have already created the attachments section - this is just for context)
How do I go about achieving this in MS Access 2013? I cannot seem to figure out nor find anything which deals with this specific problem.
The "Generate Letter" button should produce a pop-up form. That form will have either a combobox or listbox (depending on what you see fit) that displays the list of available templates, as well as an "OK" button.
Alternatively, you can place the combobox/listbox on the main form and the "Generate letter" button next to it, assuming your main form has a subform that's displaying the data.
You will then do a Mail Merge with only the active record. Once that's done, the most difficult part will be storing the "Save To" path in one of the fields. You could possibly use an OLE field, but saving the path to the file is my preferred method. I say it's the most difficult part because I'm not sure how you can capture that without using a standard dialog box.
For the word merge and selection of a template, try my super easy word merge example here:
The sample I have can be found here:
http://www.kallal.ca/msaccess/msaccess.html
Above sample is specially designed to enable ANY form with ONE LINE of code.
Thus, each time you build a new form, you can word merge enable it with great ease. (with one line of code).
Make sure you read the instructions from above, and you should eventually get to the following page
http://www.kallal.ca/wordmerge/page2.html
The above handles all of your issues a requests with the exception of the last step in which you save the path name to the document (and I recommend you don’t save the document in the database – but only path names to a folder). Grabbing the file name is also possible with my sample.

MS-Access: Force error checking before leaving a form page

I'm using MS-Access 2013 to develop a computer-aided personal interview form. Given the length of the interview it seemed to make the most sense to use multiple pages (tabs) within a form to aid user navigation. The problem with that is that the data error checking (either out of range checking, or missing entry checking) doesn't take place until you try to close the form (which might mean that an error on page 1 won't be "flagged" until (e.g.) page 10. Is there some way to "force" Access to do error checking on the fields on a given page before allowing the user to proceed to the next page?
Hook the Unload event of the form, and call your validation routine there.
If you need to validate between tabs, hook the Tab.Change event.
Use The Before Update Event of each field to validate that field before changes are written. Record The Previous Tab And Next Tab With the On Click Event. Test for missing fields before setting next tab to previous tab as skipped fields will not fire the before update validataion.

AngularJS : Dynamically update a JSON file and refeed autosuggest with it

Let's say I have a form for editing a furniture.
In my business logic, a furniture can have finishings.
In my ORM logic, "finishing" is a separate entity from "furniture", with a many-to-many relationship.
So in my "edit/furniture" form I present the user a "finishings" subsection,
with 2 UI (form) elements:
an autosuggest field, feeded by finishings.json (a file),
allows the user to attach already existing finishings to the furniture being edited,
a "+" button, that make fields appear, to enter one or more finishings.
allows the user to add finishings on the fly.
I want the user to be able to add finishings without leaving the "furniture/add[edit/$id]" REST url, so he doesn't experience a page reload.
To this end, I use the "form within form" trick, which means I'm not submitting the entire furniture form : I don't want the user to leave the page, nor do I want it to reload it. So the "submit new finishing" is a fake submit button that triggers the "finishing/add/" REST url. The REST part of the app is responsible for rewriting an updated finishings.json file that reflects the modified DB. Pretty standard stuff.
The real trick is : I would like the autosuggest field to reflect changes in realtime, doing this by "re-reading" the finishings.json file.
Here are 2 options:
Instead of the "form within form", I could just update the UI and push new finishings entries into a JSON object built upon the initial finishings.json file reading. I could push the new entries into this $scope object which would give the UI what it needs. Upon submitting the "edit furniture" form, I would prep data and sort stuff out: go through every finishing attached bu the user to the furniture, and separate the existing ones from the "just added" ones.
I keep my "form within form", because I want my finishings.json file, not a json object, to be the "source of truth".
I think I can manage option 1, but I'd really prefer to go with 2.
How would you do that?
What is the proper way in AngularJS to reload the finishings.json file on demand, and having it refeed the autosuggest with a fresh new batch of options, in real time?
Is the purpose of having this fresh data from the finishings.json file to enable every application user to be aware of new data in that file?
I mean... if me as user A am adding a new finishing, you want my finishing to be accounted by every other application user? Is that part of the suggestion algorithm?
If this is the case, and in fact what you're looking for is some sort of changes listener, you would have two options to solve this:
a) Using $timeout to pool the file every x seconds (I personally don't like this kind of approach).
b) Create a service that uses some form of WebSockets implementation (Socket.io, SignalR, etc). At an high level it would work this way: Your clients connect to the socket server/hub and subscribe to a data change event. Then, everytime a finishing is added to the file, you would then emit a data change event to the socket server which in turn would broadcast that event to every connected client.

Is there a design pattern for this...?

When a user selects a record in a datagrid I launch a pop-up window with more detailed info. The user can make changes to the record in this window but they don't have to save them. For example, they can click the X to close the window.
Unfortunately, I am stupid and whenever a user makes changes I update the object directly.
Is there a pattern for copying the object and then mapping the changes to it when a user confirms they want to save?
Thanks!
I wouldn't go with copy and merge. Why don't you just update the object only if the user explicitly wants to update/save? Let the UI be UI and condense the relevant information from it as soon as you need it.
Another way that may be appliable, if you want something like temporary edits, would be using commands for every atomic update, where every command has an inverse - undo - command. If you keep these in a history, you could just go back to the initial state.