Connecting Tech Pros Worldwide Help | Site Map

CancelEvent problem

Maarten van der Cammen
Guest
 
Posts: n/a
#1: Nov 12 '05
Hi all,

Can anyone give me suggestions on the following: (It should be very simple,
but i don't see it...)

When a user changes a value using a combo box, i want him or her to have the
possibility to cancel the change.

I tried to do so via the code below:



Private Sub NameWerkzaamhedenIDPerSubjectID_BeforeUpdate(Cance l As Integer)

If MsgBox("Do you really want to change this record?", vbOKCancel) =
vbCancel Then

DoCmd.CancelEvent

End If

End Sub



However, this does not seems to work, the combo box only shows the newly
selected data after pressing the "cancel" button, instead of the original
data.

What going wrong here?

I appreciate any suggestions,

Kind regards,

Maarten


Salad
Guest
 
Posts: n/a
#2: Nov 12 '05

re: CancelEvent problem


Maarten van der Cammen wrote:
[color=blue]
> Hi all,
>
> Can anyone give me suggestions on the following: (It should be very simple,
> but i don't see it...)
>
> When a user changes a value using a combo box, i want him or her to have the
> possibility to cancel the change.
>
> I tried to do so via the code below:
>
> Private Sub NameWerkzaamhedenIDPerSubjectID_BeforeUpdate(Cance l As Integer)
>
> If MsgBox("Do you really want to change this record?", vbOKCancel) =
> vbCancel Then
>[/color]

'remove this line
DoCmd.CancelEvent
'and insert this
Cancel = True
[color=blue]
>
> End If
>
> End Sub
>
> However, this does not seems to work, the combo box only shows the newly
> selected data after pressing the "cancel" button, instead of the original
> data.
>
> What going wrong here?
>
> I appreciate any suggestions,
>
> Kind regards,
>
> Maarten[/color]

Larry Linson
Guest
 
Posts: n/a
#3: Nov 12 '05

re: CancelEvent problem


The reason you have a "Cancel" argument on the BeforeUpdate event -- I see
it in your example -- is so you can cancel the event. You accomplish that by
setting

Cancel = True

before you exit, not with a DoCmd.CancelEvent. I'm not quite sure under what
conditions one would use a DoCmd.CancelEvent, but this isn't the
circumstance.

Larry Linson
Microsoft Access MVP


"Maarten van der Cammen" <mvdcammen@zonnet.nl> wrote in message
news:7vFMb.148192$_x2.318082@zonnet-reader-1...[color=blue]
> Hi all,
>
> Can anyone give me suggestions on the following: (It should be very[/color]
simple,[color=blue]
> but i don't see it...)
>
> When a user changes a value using a combo box, i want him or her to have[/color]
the[color=blue]
> possibility to cancel the change.
>
> I tried to do so via the code below:
>
>
>
> Private Sub NameWerkzaamhedenIDPerSubjectID_BeforeUpdate(Cance l As[/color]
Integer)[color=blue]
>
> If MsgBox("Do you really want to change this record?", vbOKCancel) =
> vbCancel Then
>
> DoCmd.CancelEvent
>
> End If
>
> End Sub
>
>
>
> However, this does not seems to work, the combo box only shows the newly
> selected data after pressing the "cancel" button, instead of the original
> data.
>
> What going wrong here?
>
> I appreciate any suggestions,
>
> Kind regards,
>
> Maarten
>
>[/color]


Fletcher Arnold
Guest
 
Posts: n/a
#4: Nov 12 '05

re: CancelEvent problem


"Maarten van der Cammen" <mvdcammen@zonnet.nl> wrote in message
news:7vFMb.148192$_x2.318082@zonnet-reader-1...[color=blue]
> Hi all,
>
> Can anyone give me suggestions on the following: (It should be very[/color]
simple,[color=blue]
> but i don't see it...)
>
> When a user changes a value using a combo box, i want him or her to have[/color]
the[color=blue]
> possibility to cancel the change.
>
> I tried to do so via the code below:
>
>
>
> Private Sub NameWerkzaamhedenIDPerSubjectID_BeforeUpdate(Cance l As[/color]
Integer)[color=blue]
>
> If MsgBox("Do you really want to change this record?", vbOKCancel) =
> vbCancel Then
>
> DoCmd.CancelEvent
>
> End If
>
> End Sub
>
>
>
> However, this does not seems to work, the combo box only shows the newly
> selected data after pressing the "cancel" button, instead of the original
> data.
>
> What going wrong here?
>
> I appreciate any suggestions,
>
> Kind regards,
>
> Maarten[/color]


Maarten
In general, when you see a sub with an argument of Cancel
eg cboCombo_BeforeUpdate(Cancel As Integer)
You need to write Cancel = True
to cancel.

However, I'm not sureyou are writing code for the right event. You could use
the combobox's AfterUpdate event like this:

Private Sub cboWhatever_AfterUpdate()

If MsgBox("Update?", vbExclamation Or vbYesNoCancel, _
"Confirm") <> vbYes Then
Me.cboWhatever.Value = Me.cboWhatever.OldValue
End If

End Sub


But more sensible might be the form's BeforeUpdate event, rather than
checking each control (I assume this is a form bound to the data)

Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Update?", vbExclamation Or vbYesNoCancel, _
"Confirm") <> vbYes Then
Cancel = True
End If

End Sub


Fletcher


Closed Thread