How does Access handle the updates on my Forms? (3 Viewers)

JMongi

Active member
Local time
Yesterday, 21:24
Joined
Jan 6, 2021
Messages
802
And I appreciate having multiple viewpoints on the best way to not only approach a problem but structure the environment of said problem. It helps me improve my overall knowledge and it's always good to have multiple approaches.
 

Isaac

Lifelong Learner
Local time
Yesterday, 18:24
Joined
Mar 14, 2017
Messages
8,738
And I appreciate having multiple viewpoints on the best way to not only approach a problem but structure the environment of said problem. It helps me improve my overall knowledge and it's always good to have multiple approaches.
Well said. No need to apologize, it's very, very healthy in tech learning to get multiple viewpoints. I always used to say, when I used UtterAccess.com mostly to ask questions, I learned the most when people went on long soapboxes or several people disagreed--that way I got 2 or 3 times as much information! :)
 

JMongi

Active member
Local time
Yesterday, 21:24
Joined
Jan 6, 2021
Messages
802
:ROFLMAO: The irony is that I'm usually the one on the soapbox. Either that or frustrating people by answering their yes or no question with a paragraph of text! o_O

I'm well aware of my foibles. I guess the good news is that its made me pretty good at disseminating information to newbies once I understand the topic myself. Gets me teased sometimes though....by my wife! :LOL:
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:24
Joined
Feb 19, 2002
Messages
42,981
I also almost never have multiple forms open at one time and when I do, the "active" form is modal so you have to close it to get back to the form that opened it.

Me. is clear and explicit and leaves no question. the Runcommand depends on the "active form",
That is all well and good EXCEPT that if you are running code in a form's class module, THAT is the active form.

PS, I once had a programmer on my team that coded his transaction so that the user could not exit without saving and had no way to correct the data. He brought down the entire CICS system.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:24
Joined
Feb 28, 2001
Messages
27,001
For the Navy system that was my most recent big project, the rule was that the user had to explicitly save or cancel any inputs. I had sense whether the form was dirty and if so, to block of navigation, the upper-right X to close the form, and I had a separate CLOSE command that would go invisible if the form was dirty. I also blocked the update at BeforeUpdate so that if the user hadn't used the save button, the form (and Access) would refuse to close. I couldn't stop a shutdown due to power or certain other uncontrollable events, but the idea was that since the result had to do with system security, there could be no accidental updates.

I bring that up ONLY because it was a real P.I.T.A. to block off all of the ways that Access would support a save operation via implicit triggers. At least I didn't have to worry about Me.Dirty diddling because the users couldn't see the code. On the other hand, once I got it working right, the users actually liked the fact that they could only do what the form thought they were ready to do. The "not ready" buttons would vanish or appear based on form context. It is not for the faint of heart, but it had a relatively good "look and feel" and responded pretty well.
 

Isaac

Lifelong Learner
Local time
Yesterday, 18:24
Joined
Mar 14, 2017
Messages
8,738
That is all well and good EXCEPT that if you are running code in a form's class module, THAT is the active form.
I would disagree on that. Just because code is executing in a particular form's class module, that doesn't guarantee that it will be seen as the active form - I think the active form is more about the focus.
 

JMongi

Active member
Local time
Yesterday, 21:24
Joined
Jan 6, 2021
Messages
802
Better change my sub-name to "Pot Stirrer" :coffee::sneaky:
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:24
Joined
Feb 19, 2002
Messages
42,981
is more about the focus.
Why would you ever open a form BEFORE you execute the code to save the current record? I suppose you could open the form first and if you don't open it as model, your code will continue running and may eventually get to the save command. In that case, you deserve what you get. This isn't an Access bug, it is a human bug. Using the "Me.Dirty" trick isn't wrong but it also isn't obvious and isn't necessary if you simply do things in a logical order. I'm sure we can code lots of bugs by ignoring logic. Use it if you want to.
 

JMongi

Active member
Local time
Yesterday, 21:24
Joined
Jan 6, 2021
Messages
802
I'm certainly no expert, but I feel we might not be EXACTLY talking about the same scenarios. So, perhaps let's narrow down my broad question to a more focused one that pertains to my particular project. My project will eventually have a login, some kind of switchboard/menu for launching the various applications (right now an equipment maintenance app and a project hour tracker app). I presume I will perform some behind the scenes shenanigans to hide the switchboard upon application launch. So let's go from there assuming my project hour tracker has been launched. We now get this:
FrmProjList.PNG

The only thing currently missing are a checkmark toggle for showing/unshowing archived projects and a "New Project" button (modal data entry form for Project creation).

Clicking on the "Edit Hours" button launches this form (cleary a work in progress):
ProjectHoursForm.PNG

This form is based on a query and requires the master project list to be open as it passed projID to the query to limit the results to the appropriate project.
So, now I have two open forms. To add a new task entry, I want the user to click on the plus button. This will open a third form that will look something like this:
ProjHoursAdd.PNG

This would be modal.

So a user would save or cancel their new task entry.
Aside from that, I'd like to provide a master edit possibility for admins to edit the individual task hours in one go (believe me, corrections from the shop floor WILL happen...wrong employee, wrong hours, etc) or delete a task entirely if it was added incorrectly.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:24
Joined
Feb 19, 2002
Messages
42,981
1. When you open a popup form, use the where argument in the OpenForm method. If you might not have "subform" records, use a left join to the parent table. This will make the form open "empty" so you can add items.

2. Never dirty a form opened this way with your own code. Wait until the user dirties it himself, THEN and ONLY THEN, populate the foreign key. That way, the user will be conscious that he did something and if you won't let him save the record because it is incomplete, the error will make sense to him. When you dirty the record with your code, the user is confused because he KNOWS he didn't touch anything and why are you bugging him? Use the popup form's on Dirty event to populate the FK. You can do that by referencing the calling form:

Me.CustID = Forms!frmMain!CustID

OR, if you prefer or if the popup might be called from multiple forms, then pass in the CustID in the openArgs property:

Me.CustID = Me.OpenArgs
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:24
Joined
Feb 19, 2002
Messages
42,981
Me. is clear. However the result of setting the property to False could just as easily be "undo" as "save" Both Undo and Save actions set Me.Dirty to false but the converse is not true.

I don't use the "trick". If you want to use it, fine, but I recommend adding a comment that the command is actually saving the record rather than undoing the changes.
 

JMongi

Active member
Local time
Yesterday, 21:24
Joined
Jan 6, 2021
Messages
802
@Pat Hartman - I'm not sure if this was meant for this thread or not. Since your last post was a month and a half ago I thought I would ping you just in case.

Ironically, after being pulled away from this project by my primary responsibility, I'll likely be returning to this in a week or two. So it works out either way. I will parse it when I need a break from CAD work.
 

Users who are viewing this thread

Top Bottom