Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping the code execution of all modules?

Status
Not open for further replies.

Bresart

Programmer
Feb 14, 2007
314
ES
Hi, i have a form with two subforms, the first one shows four fields records and the second one has a copy icon for copying and pasting the records in the first subform.

I need to stop from the AfterUpdate event of the first subform the procedure on the OnClick event of the copy icon in the second subform.

I have tried with End, but i think it only works for the module which it is in.

Any other way of making the procedure in the second subform stop from the procedure in the first subform?

Thanks for any help given.
 
I'm not sure how you are managing to trigger the afterupdate event.

I would run a query to append to the recordset of the first subform and then requery that subform.

I am guessing you did something else to do your copy.
 
Thanks lameid. No, i am not trying to trigger the afterUpdate event of the first subform. It enters when clicking in the second form icon, if any record modification has been done.

If the current record in the first subform is a new record and it is incomplete, the BeforeUpdate event shows a confirm dialog box for either cancelling the subform updating and going to the empty field to be filled, or deleting the incomplete record which is made from the afterUpdate event.

When this second thing occurs, the copy-paste action has no sense, because the previous current record has been deleted. That is for what the copy-paste action must be stopped.








Dim readDiv, readSubdiv, readCla, readSubcla, readSuperOr, readOr, readFam As String

readDiv = Me.Parent.Form.Secundario70.Form.division
readSubdiv = Me.Parent.Form.Secundario70.Form.subdivision
readCla = Me.Parent.Form.Secundario70.Form.clase
readSubcla = Me.Parent.Form.Secundario70.Form.subclase
readSuperOr = Me.Parent.Form.Secundario70.Form.superorden
readOr = Me.Parent.Form.Secundario70.Form.orden
readFam = Me.Parent.Form.Secundario70.Form.familia
clicOnCopPastTxInt = True
DoCmd.GoToRecord , , acNewRec
clicOnCopPastTxInt = False
Me.Parent.Form.Secundario70.Form.divisionTxt.Value = readDiv
Me.Parent.Form.Secundario70.Form.subdivisionTxt.Value = readSubdiv
Me.Parent.Form.Secundario70.Form.claseTxt.Value = readCla
Me.Parent.Form.Secundario70.Form.subclaseTxt.Value = readSubcla
Me.Parent.Form.Secundario70.Form.superordenTxt.Value = readSuperOr
Me.Parent.Form.Secundario70.Form.ordenTxt.Value = readOr
Me.Parent.Form.Secundario70.Form.familiaTxt.Value = readFam
 
So if the update is cancelled on the Before update event, you want to prevent the code from running?

I would use a global boolean variable.

Initialize it on the on open event of the main form and the got focus event for the form of the first subform. Set it during the before update event in question if it is cancelled. Finally test it in your copy code.
 
Thanks lameid. I have already tried using a boolean, but in order to use the copy-paste procedure even if the first subform hasn't been updated previously, i would need to set the value of the boolean from another place as well as from the beforeUpdate event.

This another place can't be the onCurrent event of the first subform, because when deleting a record this event enters three times, and enabling a counter seems too ugly, and also it would have to distinguish anyway when the first subform has been updated and when not.
 
How are ya Bresart . . .

There are two main rules I see governing your code here.
[ol][li]You don't want to copy a record in [blue]Edit Mode[/blue].[/li]
[li]You don't want to copy a [blue]New record[/blue].[/li][/ol]
So try this:
Code:
[blue]   Dim readDiv, readSubdiv, readCla, readSubcla
   Dim readSuperOr, readOr, readFam As String, sfrm As Form
   
   Set sfrm = Me.Parent.Form.Secundario70.Form
   
   [purple][b]If (Not sfrm.Dirty) And (Not sfrm.NewRecord) Then[/b][/purple]
      readDiv = sfrm.division
      readSubdiv = sfrm.subdivision
      readCla = sfrm.clase
      readSubcla = sfrm.subclase
      readSuperOr = sfrm.superorden
      readOr = sfrm.orden
      readFam = sfrm.familia
      
      clicOnCopPastTxInt = True
      DoCmd.GoToRecord , , acNewRec
      clicOnCopPastTxInt = False
      
      sfrm.divisionTxt.Value = readDiv
      sfrm.subdivisionTxt.Value = readSubdiv
      sfrm.claseTxt.Value = readCla
      sfrm.subclaseTxt.Value = readSubcla
      sfrm.superordenTxt.Value = readSuperOr
      sfrm.ordenTxt.Value = readOr
      sfrm.familiaTxt.Value = readFam
   End If
     
   Set sfrm = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Thanks TheAceMan1. I have solved it by transfering the lines

Me.Requery
DoCmd.GoToRecord , , acLast

from the AfterUpdate event of the first subform to the icon OnClic event of the second subform.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top