Stop execution of code in VBA

G

Guest

Senario: I have a form that I am duplicating using the copy/paste append method

Problem: Some of the fields have events in their afterupdate setting which causes them to trigger when the form is paste appended

Question: is there a way to stop the code form running after the record has been appended

Thanks in advance
 
B

berk

Not sure if I understand, but after the append code runs,
whether it is a sub or a function, use the Exit Sub or
Exit Function statements.
-----Original Message-----
Senario: I have a form that I am duplicating using the copy/paste append method

Problem: Some of the fields have events in their
afterupdate setting which causes them to trigger when the
form is paste appended
Question: is there a way to stop the code form running
after the record has been appended
 
G

Guest

Thanks for the reponse, I am including the code that I am using. Basically the problem is that when the paste append is invoked, it paste data into a field that has an event in the afterupdate property. So when the field is updated, the event kicks an email and another form. What I would like to do is to disable code from executing before the append> null out the fields that triggering the execution> then turn the code execution back on.

Private Sub Command178_Click()
On Error GoTo Err_Command178_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append


Exit_Command178_Click:
Exit Sub

Err_Command178_Click:
MsgBox Err.Description
Resume Exit_Command178_Click

End Sub

Thanks
Jason
 
B

berk

Now "maybe" I understand. Here is how I transfer current
information on a form onto a new form. Create a command
button that will "Add" a new record. Go to the on click
event and paste the following. (This code is assuming
there are only 3 fields on the form and that all 3 fields
will copy to the new form.)

dim tField1
dim tField2
dim tField3

tField1 = txtYourField1
tField2 = txtYourField2
tField3 = txtYourField3

DoCmd.GoToRecord , , acNewRec

txtYourField1 = tField1
txtYourField2 = tField2
txtYourField3 = tField3

This code basically copies the values of your fields into
variables. Then takes those variables and assignes them
into the newly created record.

Let me know if I'm not even close to what you are trying
to do.
-----Original Message-----
Thanks for the reponse, I am including the code that I
am using. Basically the problem is that when the paste
append is invoked, it paste data into a field that has an
event in the afterupdate property. So when the field is
updated, the event kicks an email and another form. What
I would like to do is to disable code from executing
before the append> null out the fields that triggering
the execution> then turn the code execution back on.
 
G

Guest

You are right on track. The only reason I did not do it that way is because I have to apply this to 2 forms with 60 fields each. I set one form up with the variables and set the variables. The problem I ran into is when I field was empty I would get the message Invalid use of null. I would assume I would have to test each field for null before setting the value. With that thought I was looking for a faster/simpler solution.

Thanks for your help
Jason S
 

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