Which Event? (1 Viewer)

AlexN

Registered User.
Local time
Today, 17:22
Joined
Nov 10, 2014
Messages
302
Hi all,
I have a combo in a form, where I enter values either by picking one from the list or writing a new one (on NotInList). Saved values may also change in the future.
I want to trigger a procedure (besides saving the record) after saving a new value, or changing an existing one, without adding a new button (if possible). I wonder under which event of this combo I should put the code. (I know AfterUpdate or OnDirty won't always do the job).


Thank you all
 

Ranman256

Well-known member
Local time
Today, 11:22
Joined
Apr 9, 2015
Messages
4,339
I don't follow,
you want to pick a value in a combo, then use the event to add more values to the combo?
or
add new values to a different table? (combo has only 1 value)
 

AlexN

Registered User.
Local time
Today, 17:22
Joined
Nov 10, 2014
Messages
302
I want to add a value to another table. This value won't be the same with the one picked by the combo but depending on it.
But...
It doesn't really matter what I want to do. It's when and how I can trigger the code to do it that matters.
Let's say the combo picks full names from a client list (or adds new ones through the code behind its NotinList event, and besides saving this record to the underlying table, I want to add clients first name to another table (this is an example).
I want to know under which event I should put the code, since AfterUpdate or OnDirty won't trigger always, and OnChange will trigger multiple times if I enter a non existing value in the combo.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:22
Joined
May 21, 2018
Messages
8,463
Why would after update be I insufficient?
 

AlexN

Registered User.
Local time
Today, 17:22
Joined
Nov 10, 2014
Messages
302
Because AfterUpdate only triggers if you enter a value by typing in and not if you choose it from a list. Same thing happens with OnDirty also (well almost).
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 15:22
Joined
Jan 14, 2017
Messages
18,186
Add another _Click event as follows

Code:
Private Sub ControlName_Click()
   ControlName_AfterUpdate
End Sub
 

AlexN

Registered User.
Local time
Today, 17:22
Joined
Nov 10, 2014
Messages
302
Add another _Click event as follows

Code:
Private Sub ControlName_Click()
   ControlName_AfterUpdate
End Sub



You mean I should put the code under the AfterUpdate event and then put your suggestion under the OnClick to force AfterUpdate triggering? Am I close?
 

isladogs

MVP / VIP
Local time
Today, 15:22
Joined
Jan 14, 2017
Messages
18,186
That's exactly what I meant though in fact this may work better

Code:
Private Sub ControlName_Change()
   ControlName_AfterUpdate
End Sub

I've used this myself in a few places & it did the job!
 

AlexN

Registered User.
Local time
Today, 17:22
Joined
Nov 10, 2014
Messages
302
That's exactly what I meant though in fact this may work better

Code:
Private Sub ControlName_Change()
   ControlName_AfterUpdate
End Sub
I've used this myself in a few places & it did the job!



That's brilliant isladogs!!!
It would have never cross my mind. Thank you so much!!!
 

AlexN

Registered User.
Local time
Today, 17:22
Joined
Nov 10, 2014
Messages
302
isladogs your idea was perfect! I didn't use the OnChange event though, because there's also a NotInList event firing some code. I rather used the DoubleClick event just to prevent code from firing on an accidental click.


Thank you all for your contribution!
 

Users who are viewing this thread

Top Bottom