Trigger a Function on Leaving This Record?

H

HumanJHawkins

I have a form with a "Notes" subfield. The notes subfield requires an
"Add Note" button so that a function can be run to drop the user name
and date into the note. Because of this, the user is not typing
directly into a Note field, and no automatic saving of the note record
happens.

So, if a user types a note and then goes back to the main form and
moves to a different record, their note text is still in the edit box
waiting for them to click the "Add Note" button. This of course would
save the note to the wrong record.

I could clear the note text in "On current", but this would
potentially throw out a big hunk of their text without warning. And it
would go off if they refreshed the current record, which is
undesirable. I could ask if they want to save OnCurrent, except that
it is likely they would be OnCurrent of a different record in many
cases.

So what I need is an event that triggers before leaving a record,
whether or not the record has changed... None of the events I can find
on the form seem to do that from the documentation.

Is there an event I am missing, or is there a better way to go?

Thanks!
 
D

Douglas J. Steele

I'm not sure I understand your concern that you might "potentially throw out
a big hunk of their text without warning" if you put the code in the Current
event. When the Current event fires, the text will already have been saved
associated with the correct record.
 
B

Bob Quintal

Not in this case. I should have been more clear that the user is
typing their note into an unbound edit box. There is no record
associated with it until they click an "Add Note" button.

The reason for this is in part because we do not want notes to be
entered casually. Once entered, the note is locked and the user's
name is automatically attached to it. So the user must explicitly
click a button to copy their note into the actual note record.

I am basically just looking for a way to both prevent that note
text from remaining in the unbound edit box when they move to
another record, but also give them a "You have an unsaved note, do
you want to save it?" type warning before clearing it.

Thanks in advance for any help on this.
Unfortunately, there is no event upon leaving a record on a form.
What you can do is open the note form using the modal parameter of
the openform method, so that until the user closes the unbound form
by clicking a save and close or cancel and close button, he cannot
reactivate the main form.
 
H

HumanJHawkins

I'm not sure I understand your concern that you might "potentially throw out
a big hunk of their text without warning" if you put the code in the Current
event. When the Current event fires, the text will already have been saved
associated with the correct record.

Not in this case. I should have been more clear that the user is
typing their note into an unbound edit box. There is no record
associated with it until they click an "Add Note" button.

The reason for this is in part because we do not want notes to be
entered casually. Once entered, the note is locked and the user's name
is automatically attached to it. So the user must explicitly click a
button to copy their note into the actual note record.

I am basically just looking for a way to both prevent that note text
from remaining in the unbound edit box when they move to another
record, but also give them a "You have an unsaved note, do you want to
save it?" type warning before clearing it.

Thanks in advance for any help on this.
 
H

HumanJHawkins

Unfortunately, there is no event upon leaving a record on a form.
What you can do is open the note form using the modal parameter of
the openform method, so that until the user closes the unbound form
by clicking a save and close or cancel and close button, he cannot
reactivate the main form.

I think I have another way, but I am having trouble implementing it...
I created a function for "OnDirty" of the unbound edit box. This
function should set the main form "Dirty" bit to rue. Then, in the
main form, I can have a "BeforeUpdate" Event handler to do the "Do you
want to save" thing.

The only trouble is that when I type into the unbound edit box, it's
"OnDirty" event is not firing. Grrr. Handling this seems like a
different topic, so I will move it to a new thread, "Unbound Edit Box
OnDirty Event Not Firing"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top