Solved

Detect last object clicked (on Access 2007 form) in BeforeUpdate event procedure

Posted on 2014-10-29
3
385 Views
Last Modified: 2014-10-29
In an Access 2007 form BeforeUpdate event procedure, is there any way of finding out the last object clicked on?  (The form's ActiveControl property doesn't do it, because BeforeUpdate fires before the object clicked on becomes active.)

In particular: on a form with a subform, clicking on the subform area triggers the main form BeforeUpdate event.  In the BeforeUpdate event procedure, I would like to know whether the subform was the last thing clicked on, so that I can tailor my mainform validation accordingly.
0
Comment
Question by:MatthewNicoll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40411650
Not unless you store this sort of data somewhere. If you truly must do that, then you can create a Form-level varialbe and use code like this in the OnExit event of each control:

sLastControl = Me.Name

Assuming the Form-Level variable is named "sLastControl", of course.

That said: You refer to "Mainform Validation", but you'd not be able to do that from the Subform, since by the time you hit the Subform the data in the Mainform has already been saved - so there'd be no need to validate, since you really couldn't do much about it.

In most common scenarios, you'd validate the Parent record BEFORE you add or modify a CHILD record. This is the reasoning behind the event sequence in Access.

However, if you could explain further about why you need to hold off on validating a Parent until the user has interacted with the Child, we might be able to dig a little deeper.
0
 

Author Closing Comment

by:MatthewNicoll
ID: 40411777
Thanks Scott.  I just wanted to make sure there wasn't some Form property I had missed.
Basically, I wanted to let the user fill in main and sub form information in any order before doing validation, if possible.
(... and without unbinding all the controls!)
0
 
LVL 85
ID: 40412031
You can validate at any point, but if you do it AFTER you update the data, then there's really not much you can do about it - unless, of course, you're storing old values somewhere, and can "revert" them. Still, if you need that sort of control you're often better off using temporary tables, or moving to an unbound form.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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