A better mouse trap?

ghudson

Registered User.
Local time
Today, 01:58
Joined
Jun 8, 2002
Messages
6,194
As developers, we have a challenge to prevent our users from advancing to another record if they do not use the navigational controls we want them to use or to prevent them from bypassing our validation procedures too ensure the current record is okay to be saved. The invention of the scrolling mouse wheel has given most developers (not using Access XP) a challenge to control the users ability to bypass most data validation procedures.

My sample will prevent the user from using the following functions if the current record has been modified but was not saved using my custom save button...
  • Advance to another record using their scrolling mouse wheel
  • Advance to another record using the default or custom navigation buttons
  • Use the Page Up or Page Down keys
  • Use the Shift-Enter key combination to save the current record
  • Use the F9 key (refresh records)
  • Use toolbar options relevant to record operations (sort, find, etc.)
  • Close the form
The trick in my sample is the value in the tbProperSave text box. My method ensures the user can not leave the current record if it has been modified unless they save or undo the changes to the current record using my custom save or undo buttons. This also allows you to add your own validation steps to ensure the current record is okay to be saved if it passes your validation procedures.

My method does not use ActiveX, .DLL's or a lot of VBA. My method does not disable the users scrolling mouse wheel, it only prevents the scrolling mouse wheel from advancing to another record if the current record has been modified but not saved using my custom save button.

Please post back if you have any comments or suggestions. Thanks!
 

Attachments

A better mouse trap? - With SubForms

The attached sample has a new form with a subform. I can easily trap if the user modifies a record in the main form or subform and then attempts to move off the current record (or subrecord) without using my custom save or undo buttons.
 

Attachments

Mouse trap question

Ghudson

This mouse trap is excellent but I THINK I found one loophole.

If you change the first name and press save and then change the second name and use the mouse wheel to scroll to another record, it does this without showing the warning. Is this a known problem or just me?!
 
andrewf10,

Yes, your example will circumvent the Mouse Trap because the tbProperSave value has not been reset back to "No" after the current record was saved.

Modify the code for the vbYes case in the bSave_Click() sub to...
Code:
        Case vbYes: 'Save the changes
            Me.tbProperSave.Value = "Yes"
            DoCmd.RunCommand acCmdSaveRecord
            [COLOR=blue]Me.tbProperSave.Value = "No"[/COLOR]
Thanks for the feedback. I have not looked at the Mouse Trap sample in quite a long time and I am glad to see that so many people have viewed this thread and downloaded my sample.
 
ghudson said:
Thanks for the feedback. I have not looked at the Mouse Trap sample in quite a long time and I am glad to see that so many people have viewed this thread and downloaded my sample.

Take a bow!
 
That problem was driving me crazy until I saw this unzip file and it works great. I don't understand how it is working but it is. Thanks for the file. :D :D

But I do have a question. How can I put this process in my entire application instead of adding it to the Load and Unload events of all my forms.
 
Mouse trap

Ghudson
Thanks a million!
It worked okay I was able to adapt the code to suit my needs.

I am very grateful>

Do have a nice day!
 
Is there an easy way to do this in Access XP or later that I'm not aware of? I've been using your code for some Access 2003 databases.

BTW, shouldn't this be in the Sample Databases section?
 
It should be on the Microsoft KnowledgeBase, over 3 years and still going strong on all my databases :-) GHudson......R E S P E C T
 
I looked and couldn't really find what I was looking for.
 
I was joking that GHudson's post should be on it cos it's so good!
 
Thank you very much. You don't know how long i've been looking for something like this.

Really helpfull.

:D :D :D
 
Why did you use a hidden textbox ( tbProperSave ) ?

Instead I suggest you use a private variable.

Just delete that clunky textbox and instead add

Private ProperSave As Boolean

in the general declaration of your form ( just after option explicit )

Then all you need to do is change the

Me.tbProperSave.Value = "Yes"
Me.tbProperSave.Value = "No"



for

ProperSave = True
ProperSave = False
 
Last edited:
I think you should know that adding quotes to Yes and No will make sure it doesn't work
 

Users who are viewing this thread

Back
Top Bottom