Solved

Access 2007 BeforeUpdate event firing unexpectedly

Posted on 2014-10-28
4
255 Views
Last Modified: 2014-10-29
Access 2007, Windows 7

I have a main form with a subform.
I do some validation in the mainform BeforeUpdate event procedure.
If the validation fails, I set Cancel = True in the BeforeUpdate procedure.

In the following sequence of events:

1 - focus is on mainform bound textbox A
2 - I click on a subform textbox
3 - mainform BeforeUpdate event fires (dirty=True)
4 - validation fails, (because another required field is blank),
    a msg is displayed (via a VBA msgbox statement),
    Cancel is set to True in the BeforeUdpate procedure.
5 - focus returns (automatically) to mainform textbox A
6a - if I now TAB to mainform bound textbox B, focus moves quietly to B
6b - but if instead I CLICK on mainform textbox B,
     the mainform BeforeUpdate event fires again, (dirty=True)
     and so the same validation message is displayed again.  
7  - if I click on mainform textbox B again, BeforeUpdate does NOT fire.

Why does the mainform BeforeUpdate event fire in step 6b ?
0
Comment
Question by:MatthewNicoll
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40410310
Are you doing anything else in the BeforeUpdate event, like un-doing changes? That could cause the behavior ...
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40411536
So you are trying to validate the fields "on the fly", individually?.
For me, a lot of times, I will instead do all my validation at one time, ...much like what happens on most web sites.
You enter all your info, one field at a ime, (with no validation after each field is cycled)
...then, ...in the next step (example:, clicking in the subform), ...the system will prompt you about any "invalid" fields.

But going back to yor original question,
...You did not post your code, so it is hard to tell if that is where the flaw lies...
0
 

Author Comment

by:MatthewNicoll
ID: 40411551
The validation routine I called from the BeforeUpdate event routine did a check which involved a query on the same table that the main form is bound to.  Removing that code helped: the behaviour described in my question now only happens ONCE after a record becomes current.  I'll have to be satisfied with that.  Thanks for your suggestion Scott.
0
 

Author Comment

by:MatthewNicoll
ID: 40411577
Jeffrey: it is a large form, and there is a lot of code!  I do most of the validation in a routine called in the BeforeUpdate routine.  The trouble is that moving from the main form to a sub-form triggers BeforeUpdate, at which point I don't really want to do all the validation.  (I may ask a separate question about that!)  In the past I have realized that if I want complete control, I have to use unbound controls, but that is not an option at the moment.  Thanks for your comments.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question