How to know if a button was pressed at beginning of field_AfterUpdate?

Maa421s

New member
Local time
Today, 18:03
Joined
Jun 28, 2013
Messages
7
Here is my problem

In namefield_AfterUpdate, I check for duplicate name entries and notify the user if any are found - they are prompted as to whether the duplicate was accidental or intentional and continue working. This works fine for normal circumstances.

However, if the user updates namefield so that the value is a duplicate of an existing name in the database, but then presses Cancel (or Delete), then the namefield_AfterUpdate is fired and I have no idea what button they pressed. The button Click code does not run first.

How can I tell if the user updated the name, but then realized they didn't want to save, and then clicked 'Cancel' (or any button) and the code should really skip the duplicate check validations/messages?

Hope this makes sense. Running XP or Win7 with A2007
 
Perhaps it would be better to do the field validation in the control's Before Update event rather than the After Update event.
 
Here is my problem

In namefield_AfterUpdate, I check for duplicate name entries and notify the user if any are found - they are prompted as to whether the duplicate was accidental or intentional and continue working. This works fine for normal circumstances.

However, if the user updates namefield so that the value is a duplicate of an existing name in the database, but then presses Cancel (or Delete), then the namefield_AfterUpdate is fired and I have no idea what button they pressed. The button Click code does not run first.

How can I tell if the user updated the name, but then realized they didn't want to save, and then clicked 'Cancel' (or any button) and the code should really skip the duplicate check validations/messages?

Hope this makes sense. Running XP or Win7 with A2007

if they press delete or cancel, they are starting over, so you should do your tests again, I trhink.

validation is certainly better done in the beforeupdate, not after update event


ie this does not accept the input, and waits for further action.

Code:
sub control_beforeupdate(cancel as integer)
 
if validation fails then
  cancel = true
  exit sub
end if
 
Thank you both for your suggestion. That works perfectly! Now to address the SetFocus commands...

I inherited this application, which does all validation checking in AfterUpdate events and assumed it was coded correctly. I didn't have much Access coding experience prior to this assignment. So, my assumptions and lack of experience caused this. I never would have coded it with AfterUpdate from the beginning. It makes no sense at all...
 

Users who are viewing this thread

Back
Top Bottom