PC Review


Reply
Thread Tools Rate Thread

Cancel/BeforeUpdate Event Procedure

 
 
Sprinks
Guest
Posts: n/a
 
      27th Apr 2010
I have a main form Containers with a subform ContainerSubstances. The latter
has a combo box showing the substances in the Substances table. If the
desired substance is not in the combo, the user may bring up the Substances
form in Add and Dialog mode. The user can press Save or Cancel from the
latter form, and both work as designed.

If Save is pressed, the combo box on the original subform is requeried to
include the new value, and then the new value is selected by the code, and
the Substances form closes, and the user returns to the Containers form, with
focus set in the subform. All of this works.

The Containers form has its own set of Save/Cancel buttons. If its Cancel
button is pressed, any changes made on the Main form are undone, but not the
subform, including the change to the combo box.

Private Sub cmdCancel_Click()
On Error GoTo Err_Handler

If Me.Dirty = True Then
Me.sbfContainerSubstances.Form.Undo
Me.Undo
End If

DoCmd.Close acForm, Me.Name

Err_Exit:
Exit Sub

Err_Handler:
Select Case Err.Number
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
Resume Err_Exit
End Select

End Sub

Does anyone have a suggestion? Do I need to copy the state of the subform
to an array temporarily, and reset it?

Thank you.

Best regards,
Sprinks
 
Reply With Quote
 
 
 
 
Jeanette Cunningham
Guest
Posts: n/a
 
      27th Apr 2010
The problem is that once you move the cursor out of the subform to click the
save button on the main form, that makes access trigger the subform to save
the record.
Usually this is what we all want in our apps.

Same type of thing happens when you move the cursor out of the main form
into the subform, access saves the main form.

I have very occasionally put an undo button on the subform.
You can instead write code to delete all the related subform records for
that main form record (I think I have only ever done this once).
This code would run when you click the undo button on the main form.
Then you would requery the subform.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

"Sprinks" <(E-Mail Removed)> wrote in message
news:97FBDC32-378D-4EEA-A79D-(E-Mail Removed)...
>I have a main form Containers with a subform ContainerSubstances. The
>latter
> has a combo box showing the substances in the Substances table. If the
> desired substance is not in the combo, the user may bring up the
> Substances
> form in Add and Dialog mode. The user can press Save or Cancel from the
> latter form, and both work as designed.
>
> If Save is pressed, the combo box on the original subform is requeried to
> include the new value, and then the new value is selected by the code, and
> the Substances form closes, and the user returns to the Containers form,
> with
> focus set in the subform. All of this works.
>
> The Containers form has its own set of Save/Cancel buttons. If its Cancel
> button is pressed, any changes made on the Main form are undone, but not
> the
> subform, including the change to the combo box.
>
> Private Sub cmdCancel_Click()
> On Error GoTo Err_Handler
>
> If Me.Dirty = True Then
> Me.sbfContainerSubstances.Form.Undo
> Me.Undo
> End If
>
> DoCmd.Close acForm, Me.Name
>
> Err_Exit:
> Exit Sub
>
> Err_Handler:
> Select Case Err.Number
> Case Else
> MsgBox Err.Number & vbCrLf & Err.Description
> Resume Err_Exit
> End Select
>
> End Sub
>
> Does anyone have a suggestion? Do I need to copy the state of the subform
> to an array temporarily, and reset it?
>
> Thank you.
>
> Best regards,
> Sprinks



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BeforeUpdate Cancel mac71413 Microsoft Access Form Coding 0 25th Aug 2009 03:52 PM
BeforeUpdate event: Trouble with Cancel = True Clif McIrvin Microsoft Access 14 19th Feb 2009 02:45 AM
Beforeupdate: Using a function instead of an event procedure bdtmike Microsoft Access Forms 2 26th Feb 2007 06:17 PM
Cancel Event Procedure on Button if Combo Box is Empty =?Utf-8?B?bmlja21jZA==?= Microsoft Access Forms 3 1st Mar 2005 12:55 PM
BeforeUpdate and Cancel Brad Microsoft Excel Programming 0 10th May 2004 09:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:41 AM.