Double Click event not triggering After Update event

George-Bowyer

Registered User.
Local time
Today, 05:41
Joined
Dec 21, 2012
Messages
178
I have a form with a date field, that the user can double click to fill with a certain date.

I then have code in the After Update event of the same field that adds a new record to a table if certain criteria are met.

If I double click the field, it fills as it should and saves the date as it should. However, it does not trigger the After Update event.

If I enter the same date manually that the Double Click event auto fills, the After Update is triggered as it should be.

Can anyone advise why the Double Click seems to be bypassing After Update, please??

This is the code for the Double Click:


Code:
Private Sub FldRetireDate_DblClick(Cancel As Integer)

FldRetireDate = DateSerial(Switch(Month(Date) > 4, Year(Date) + 1, True, Year(Date)), 4, 30)

End Sub

Thanks,

George
 
populating a control using vba does not trigger the after update event. Suggest you add to the code you posted

Code:
Private Sub FldRetireDate_DblClick(Cancel As Integer)

    FldRetireDate = DateSerial(Switch(Month(Date) > 4, Year(Date) + 1, True, Year(Date)), 4, 30)
    FldRetireDate_AfterUpdate
 
End Sub
 
Yep. That absolutely did the trick. Thanks.

What's the reasoning behind this?

It would seem logical to me that if you fill a field with VBA, but don't tab out of it, then the tabbing should trigger the After Update? Obviously, the Access Deities think otherwise, but I can't work out why?
 
Or you can simply add .Text like this

Code:
FldRetireDate[COLOR=Red].Text[/COLOR] = DateSerial(Switch(Month(Date) > 4, Year(Date) + 1, True, Year(Date)), 4, 30)
and the AfterUpdate will fire! Learned that yeas ago...but don't remember where!

Linq ;0)>
 
If I double click the field, it fills as it should and saves the date as it should. However, it does not trigger the After Update event.

Did you tab out of the field after the double-click changed the field's contents?

It would seem logical to me that if you fill a field with VBA, but don't tab out of it, then the tabbing should trigger the After Update? Obviously, the Access Deities think otherwise, but I can't work out why?

It is not clear from this comment as to whether you DID or DID NOT tab out of the field after the double-click.

The reasoning is that as long as the cursor is still in the field (after the double click), Access hasn't updated anything - until just before LostFocus fires. Changes to the ordinary .Value (not the .Text property as Linq suggested) aren't committed until you leave the field for elsewhere.

https://support.office.com/en-us/ar...-objects-e76fbbfe-6180-4a52-8787-ce86553682f9

Excerpt from that link: When you enter or change data in a control on a form and then move the focus to another control, the BeforeUpdate and AfterUpdate events occur.

The full sequence is BeforeUpdate ==> AfterUpdate ==> Exit ==> LostFocus

Don't forget that these are inextricably bound together. All four events will occur whether or not you have event routines for them. All you can hope to do is to have something to capture the fact of the event. But if you don't perform the triggering action, NO events fire. Now, if the double-click had included a .SetFocus to some other control? Should have fired the sequence right off.
 
Linq, that would imply that there is a way to change contents of a bound control that won't set the .Dirty flag. Is that what you are saying?
 

Users who are viewing this thread

Back
Top Bottom