I have a problem, I want to use the beforeupdate event of a combobox to
cancel
an action (using a simple msgbox warning in the event), but it doesn't seem
to work.
I even made the event routine dead simple: cancel all the time. And no
success... !!!
It seems to work a bit has the AfterUpdate event never trigger when I cancel
and
does trigger and I don't, but the value stay the same even when I cancel.
The combobox is unbound but takes it values from a query.
Help!!
Here's my dead-simple-but-doesn't-work routine:
Private Sub cboManufacturer_BeforeUpdate(Cancel As Integer)
MsgBox (Me.cboManufacturer.Value & "<vs>" &
Me.cboManufacturer.OldValue)
Me.cboManufacturer.Undo
Cancel = True
End Sub
Note: The msgbox was to show me .oldvalue & .value, and there always the
same
even if I just changed the value. Maybe it doesn't work for
unbound combobox
Thx
Stef
--
Ken Snell
<MS ACCESS MVP>
"Stef" <St...@nowhere.com> wrote in message
news:%23cnSOKe...@TK2MSFTNGP09.phx.gbl...
So how can I implement a way to "cancel" an update on a combobox?
Is there any event trigger I can rely on or I will have to manually track
the value myself and somehow (maybe AfterUpdate) find a way to revert
the change if inapropriate?
Regards
"Ken Snell [MVP]" <kthsne...@ncoomcastt.renaetl> wrote in message
news:OQ$O%23oe1F...@TK2MSFTNGP15.phx.gbl...
Declare two variables in the Declarations section of the form's module:
Private glbvarComboValue As Variant
Private glbblnChangeBack As Boolean
You could use the GotFocus event to store the current value of the combo box
into glbvarComboValue and to set glbblnChangeBack to False.
Then, in your BeforeUpdate event, when you want to "undo" the value entered,
set glbblnChangeBack to True. Then, in the combo box's AfterUpdate event,
test the value of glbblnChangeBack; if it's True, set the combo box to
glbvarComboValue value and set glbblnChangeBack to False. If
glbblnChangeBack is False when the AfterUpdate event occurs, then store the
new value of the combo box into glbvarComboValue.
Example code:
Private glbvarComboValue As Variant
Private glbblnChangeBack As Boolean
Private Sub cboManufacturer_BeforeUpdate(Cancel As Integer)
If Me.cboManufacturer = "SomeValue" Then
' not valid value
MsgBox "Invalid Value"
glbblnChangeBack = True
End If
End Sub
Private Sub cboManufacturer_AfterUpdate()
If glbblnChangeBack = True Then
glbblnChangeBack = False
Me.cboManufacturer.Value = glbvarComboValue
Else
glbvarComboValue = Me.cboManufacturer.Value
End If
End Sub
Private Sub cboManufacturer_GotFocus()
glbvarComboValue = Me.cboManufacturer.Value
End Sub
--
Ken Snell
<MS ACCESS MVP>
"Stef" <St...@nowhere.com> wrote in message
news:uhvrpAf1...@TK2MSFTNGP15.phx.gbl...
Thx... this was very informative... much appreciated
"Ken Snell [MVP]" <kthsne...@ncoomcastt.renaetl> wrote in message
news:Ot61cdk1...@TK2MSFTNGP15.phx.gbl...