473,385 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to ensure data integrity if the user closes Access

137 100+
If the user clicks the red x in the top right corner, or shuts Access via task manager, is there anyway of applying some sort of procedure for any data currently open?
If you have any dirty forms when the user closes Access, it automatically saves the file, whereas I'd rather have it undo/delete current changes - I'm trying to avoid any orphan records appearing in the database should a user close the application at the incorrect time.
I know it's possible to disable the red x button and implement my own close button, however some users might not like this, and it doesn't get round the problem of closing via task manager.

Thanks.

Adam.
Jun 7 '11 #1

✓ answered by NeoPa

Some events come with the inbuilt ability to be cancelled. Form_Open() & Form_Unload() are two such events.

The following code illustrates the technique, but shouldn't be used as is because otherwise the event would never complete :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.     Cancel = True
  3. End Sub
Typically the code should have a condition which must be met before cancelling.

9 2130
NeoPa
32,556 Expert Mod 16PB
The correct procedure for handling a user clicking on the X in the corner or using Task Manager to kill the process is really to speak to their manager to see if they can ensure they do nothing so completely stupid in future (They needn't be fired, as long as they are locked out of rooms with computers in they should be safe. See if someone can find them some buttons to count).

Of course RL often doesn't work as smoothly as that and we all know how many otherwise intelligent beings have no idea that killing a process is any more involved than avoiding that complicated question they didn't know how to answer. Sorted. Job done :-) The time spent by IT (assuming they are themselves competent) recovering from these various problems can stretch into man days sometimes and often into man hours.

None of that is particularly helpful I'm sure. If your company were enlightened enough to apply discipline to such employees I doubt you'd be asking the question in the first place ;-)

In truth, these methods are so powerful that there is little that can be done to stop a determined idiot. However, there are events (which have related event procedures) available whereby the saving of data can be cancelled (I believe it also works in this scenario but you ought to confirm for yourself). Try using the Form_Unload() event procedure (which has a Cancel parameter built-in) and only allowing the users to close a form from a Command Button you provide for them on the form (That way you can ensure they're not hitting any Xs by putting code in the event to indicate the proper Command Button was used).
Jun 14 '11 #2
Adam Tippelt
137 100+
HA, so true...unfortunately...

So basically the only option would be to disable the X button, thereby forcing them to close via my own quit buttons.
That was the only option I had found, but I was hoping to not do this - annoyingly most idiots start to panic when controls are missing that they expect to be there - they don't seem to understand that this is done for a reason, think that it's a fault, and believe that closing via Task Manager is a far more sensible option.

I'd like to think the employees understand enough about Access to stop them from doing something like that, but you always have to prepare for the worst. (If such common sense existed and we didn't need to handle idiots, it's likely that this tool would only have 1K lines of code instead of 10K)

Ah well. I'll have to hope that my design will prevent any damage to live data.
Probably a stupid question, but if the user closed Access via the X button or Task Manager, does the Form_Close event procedure run?

Thanks for the info on Form_Unload, I'll see if it helps.
Jun 14 '11 #3
NeoPa
32,556 Expert Mod 16PB
You needn't disable the X button on the form. Simply Cancel the event unless you detect it's been triggered by your command (or even send a message to use the command). In fact, you could even treat them as synonymous, but the application close is another matter.

Adam:
if the user closed Access via the X button or Task Manager, does the Form_Close event procedure run?
I'm not in a position to test that just now, but it should be easy enough to. Shove in an event procedure and see whether or not it runs.

In a rush now. Let me know how you get on or if anything else is required. I'll have more time tomorrow.
Jun 14 '11 #4
Adam Tippelt
137 100+
Oh, I wasn't aware I could just cancel the event. When you have time can you elaborate on how I would do something like that? Is it similar to the KeyDown events?
Jun 15 '11 #5
NeoPa
32,556 Expert Mod 16PB
Some events come with the inbuilt ability to be cancelled. Form_Open() & Form_Unload() are two such events.

The following code illustrates the technique, but shouldn't be used as is because otherwise the event would never complete :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.     Cancel = True
  3. End Sub
Typically the code should have a condition which must be met before cancelling.
Jun 15 '11 #6
Adam Tippelt
137 100+
Hmmm...could I use a Global boolean variable? - The variable always = false unless the user exits via the correct means, then the variable = true.

And in the unload event the condition is whether the boolean variable = false.

So the system would treat it as:

Expand|Select|Wrap|Line Numbers
  1. If user exits via correct means then
  2.  
  3. Unload event doesn't run
  4.  
  5. Else
  6.  
  7. Unload event runs.
  8.  
  9. End if.
Would that work, or am I completely misunderstanding how the Unload event is initiated/works?
Jun 16 '11 #7
NeoPa
32,556 Expert Mod 16PB
That's pretty well what I was suggesting yes.

The Command Button that you want them to use would have some code setting the variable (Private within each Form I would suggest.) to True. Until that point it would be False by default.
Jun 16 '11 #8
Adam Tippelt
137 100+
Ok cheers NeoPa, that seems like a pretty straight forward way to solve the problem.

Thanks.

Adam.
Jun 17 '11 #9
NeoPa
32,556 Expert Mod 16PB
Happy to help Adam :-)
Jun 17 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rafael Chemtob | last post by:
Hi, I'm using session cookies on my web app and it looks like the session is not being killed when the user closes the browser. We use a Global.asa file on our app. Do we have to explicitly...
0
by: Magic1812 | last post by:
Magic Software invites you to join us this coming Tuesday (January 27th, 2004) at 12:00 EDT / 17:00 GMT for a FREE live Webinar: Title: Data Integrity Using eDeveloper Date: January 27, 2004...
2
by: Brice | last post by:
Hello, Sorry if this is a basic question but I can't seem to find the answer in the DB2 tutorial series or my DB2 manuals. How does one check the data integrity and referential integrity of an...
10
by: Andrea M. Segovia | last post by:
Hello, I am a newbie to Oracle databases.... We have a visualization front-end tool connected to an Oracle back-end database on a Tru64 UNIX server. We also have clients with MS access...
5
by: news.microsoft.com | last post by:
Hi everyone, I need some help (may be in the form of some sample code) for the subject question. I have an ASP.NET/C# application. I need to do quite a few tasks when the session ends. I...
6
by: Annie | last post by:
Hi guys, I just want to do some clean up in the Session_End at Global.aspx. However, if the user closes the browser window that event is not fired. how can I call explicity protected void...
4
by: Deus402 | last post by:
I am designing an employer database, and I had thought that my tabledesign was pretty sound, but a new revelation has ruined my design. What I guess i really need is a way to uniquely identify...
1
by: lathamoulali | last post by:
Hello frnds, I am new to ASP Programming,please help me out with this problem... The site uses the same ASP file but the map is generated when using the anonymous user and other times the map...
0
by: dolittle | last post by:
In my application the browser window connect with long polling(comet) with the server. If the user open several browser tabs, only one of them(called the master) communicate with the server and...
13
by: mxtreme | last post by:
Hi folks - I am in need of help please I am trying to de-duplicate data coming from Excel to Access The part I am having problems with is (I have attached the full code at the bottom too to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.