Unwanted Form_Undo 'side effect' and form and control undo events

G

GodotIsDead

I am using Access 2003. I have a page on a tab control that contains
a subform containing therapy information. To record intravenous
therapy I have a number of bound controls, namely a combo box
'IVCannulaInserted' to record whether or not a cannula was present, a
subform 'fsub72HrIVCannula' to record usage of the cannula (if
present) and a comments textbox 'IVCannulaOther' that is enabled if
there is a subform record of 'Other' (to record information on any
usage not otherwise specified in the subform).

The subform is visible when the combobox shows a cannula is present.
The comments textbox is enabled when there is a subform record of
'Other'. On deleting an 'Other' subform record, the comments textbox
is also emptied.

1. I wanted to include an 'undo' facility and have hit a snag. When a
cannula is present, and it has a usage of 'Other' and there is an
associated comment, then if the cannula is later marked as absent
using the combobox but the person entering the data changes their mind
and hits ESC to undo changes I get the following: the subform
reappears minus any prior records (as desired), but the comments
textbox which is now not enabled (as desired since there is now no
subform 'Other' record) contains the comment relating to the prior
'Other' subform record.

The code I have currently is:

Private Sub Form_Undo(Cancel As Integer)

On Error GoTo Err_Form_Undo

'tlkpCannulaInsertion
Const conAlreadyInPlace As Byte = 1
Const conYesNewlyInserted As Byte = 2

If Not IsNull(Me.Parent![ReferralID]) Then
If Me!IVCannulaInserted.OldValue = conAlreadyInPlace Or Me!
IVCannulaInserted.OldValue = conYesNewlyInserted Then
If Me.Form!fsub72HrIVCannula.Visible <> True Then
Me.Form!fsub72HrIVCannula.Visible = True
End If
Else
Me.Form!fsub72HrIVCannula.Visible = False
End If
'Me.Form!fsub72HrIVCannula.Requery

'Prevent 'Other comment' reappearing in the absence of (the now
missing) 'Other' row in the subform (NOT WORKING as desired!)
If Me!IVCannulaOther <> "" Then
Me!IVCannulaOther = ""
End If

End If

Exit_Form_Undo:
Exit Sub

Err_Form_Undo:
Call LogError(Err.Number, Err.Description,
"fsub11_72HrInterventions_Form_Undo()")
Resume Exit_Form_Undo

End Sub

I would like to clear that comment text as part of the 'undo' but when
I try that as part of the Form_Undo it doesn't work. I guess the
actual 'oldvalue' data is only inserted into the comment textbox after
the Form_Undo event is completed. Does anyone have a suggestion for
how I might remove that unwanted comment text? I'm afraid I can't see
the wood for the trees at the moment.

2. I had wondered about whether it would be possible to limit the
'undo' to the combobox control but have been unable to get the
combobox Undo event to fire with the ESC key. I note in the help for
the Undo event:

'The Undo event for controls occurs whenever the user returns a
control to its original state by clicking the Undo Field/Record button
on the command bar, clicking the Undo button, **pressing the ESC
key**, or calling the Undo method of the specified control. The
control needs to have focus in all three cases. The event does not
occur if the user clicks the Undo Typing button on the command bar.

The Undo event for forms occurs whenever the user returns a form to
its original state by clicking the Undo button, **pressing the ESC
key**, or calling the Undo method of the specified form.'

I am puzzled, therefore, as to why the combobox Undo is not fired with
ESC, and about how the form and control Undo events interact or
whether there is any dependency or ordering between them. (I couldn't
get the combobox Undo to fire in the Show Events form of the Microsoft
sample Orders.mdb either.) I would welcome advice about these events.

Kind regards.
 

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