Solved

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

Posted on 2014-10-29
3
361 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
  • 2
3 Comments
 
LVL 84

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 84
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now