Solved

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

Posted on 2014-10-29
3
376 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

827 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