How do I trigger the before/after update event on an unbound form

domaze

Registered User.
Local time
Today, 02:39
Joined
Feb 7, 2010
Messages
29
Hi,

This is my first post ever in programmers' forums so please forgive any possible mistakes.

I've created an unbound form with 4 unbound fields.
The propose of the form is to collect the criteria to find the records in a table and duplicate(!) them. In order to do this I have some code on the form's before and after update event but I realized that these events cannot be triggered because I cannot save the record (4 unbound fields).
My question is how to make these events trigger. How does the before / after update event fire on an unbound form?

note: I could use the code I wrote in the before/after update events behind a command button to have the job done I guess but I'd realy apriciate any help on triggering the before/after update event of the form.

Thanks in advance
 
Hi,

This is my first post ever in programmers' forums so please forgive any possible mistakes.

I've created an unbound form with 4 unbound fields.
The propose of the form is to collect the criteria to find the records in a table and duplicate(!) them. In order to do this I have some code on the form's before and after update event but I realized that these events cannot be triggered because I cannot save the record (4 unbound fields).
My question is how to make these events trigger. How does the before / after update event fire on an unbound form?

note: I could use the code I wrote in the before/after update events behind a command button to have the job done I guess but I'd realy apriciate any help on triggering the before/after update event of the form.

Thanks in advance


I could use the code I wrote in the before/after update events behind a command button
:confused: Command buttons do not have these events. Did you mean the on click or on double click?


On your unbound form, how are you expecting to trigger the before/after update events?

I would expect you to use a "save" button. This would seam logical on an unbound form. It woudl also seam logical to place your code in the button's On click event.


If you must use the form's before/after update events, then change your form to be bound. I would use a temporary table.
 
thank you for your immediate response.

What i meant on the note was to put the code behind the on click event of a command button instead of the before / after update but as it seems my english are poor.
Anyhow, I tried to use a "save" button but it didn't help. Clicking on it triggered nothing.
I guess i'll have to create a temporary table.
Thanks again for your super fast response!
 
in a unbound form you have to manage the data yourself

but in a button click you could do


call the before update/append/delete code

execute sql statement

call after update/append/delete code


if this is applicable
 
in a unbound form you have to manage the data yourself

but in a button click you could do


call the before update/append/delete code
...
call after update/append/delete code
Nevermind...
 
Last edited:
gemma-the-husky, thank you a lot for the response. This was really helpful.
so let me see if I get it right.

You mean something like the following:

Private Sub Command1_Click()
call Form_BeforeUpdate(0)
call Form_AfterUpdate()
--- Run some SQL ---
End Sub

This is exactly what I was asking for but there is a new question now:
the before update sub something like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.date_m) Then Cancel = 1
...
end sub

if the variable me.date_m is indeed null the procedure form_afterupdate() will be called? I suppose it will. i think that i will just replace the variable cancel with my_cancel (global) and then the code will look like:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.date_m) Then my_Cancel = 1
...
end sub

Private Sub Command1_Click()
call Form_BeforeUpdate(0)
if my_cancel = 0 then
call Form_AfterUpdate()
--- Run some SQL ---
end if
End Sub

I'll try this and hope it works.
Again thanks a lot. you saved me much time of work.

EDIT: I called the beforeupdate and worked.
EDIT2: So did the afterupdate!
Super thanks!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom