rollback combobox to 'BeforeUpdate' value

S

Steve S

How do I set a combobox to a previous value? When finished updating a
particular record the user selects an identifer in a combobox to advance to
the next desired record. I use the BeforeUpdate event of the combobox to ask
a yes/no question. If NO I want to stay with the current record and this
works. the problem is that the combobox has been advanced to the new
selection and stays there. Now I have the identifer for one record in the
combo box but the form is still (as it should be) on the current record.

I need to roll back the combobox to what it was before the update but I
can't seem to get this part right. Tried me.bx = me.bx.oldvalue but that
generates an error message.

Also what is the difference between ' DoCmd.CancelEvent' and 'Cancel =
True'

All comments and suggestions are appreciated
 
D

Dirk Goldgar

Steve S said:
How do I set a combobox to a previous value? When finished updating a
particular record the user selects an identifer in a combobox to advance
to
the next desired record. I use the BeforeUpdate event of the combobox to
ask
a yes/no question. If NO I want to stay with the current record and this
works. the problem is that the combobox has been advanced to the new
selection and stays there. Now I have the identifer for one record in the
combo box but the form is still (as it should be) on the current record.

I need to roll back the combobox to what it was before the update but I
can't seem to get this part right. Tried me.bx = me.bx.oldvalue but that
generates an error message.

You can call the combo box's Undo method. For example:

'------ start of example code ------
Private Sub cboYourCombo_BeforeUpdate(Cancel As Integer)

If MsgBox("Did you really mean that?", vbYesNo, "Confirm") = vbNo Then
Cancel = True
Me.cboYourCombo.Undo
End If

End Sub
'------ end of example code ------

Generally, no practical difference. I believe there could be a difference
in some unusual cases, though. DoCmd.CancelEvent sends a message to Access
to cancel the most recently raised event -- at least, I think that's what it
does. I can imagine, then, that if one event is raised while another event
is still active, it is possible that DoCmd.CancelEvent might cancel the
wrong event. Executing "Cancel = True" in an event procedure that has a
Cancel argument will be specific to that event, with no possibility of
confusion.
 
S

Steve S

That did not seem to work. Here is my code.

Private Sub comboTwirler_BeforeUpdate(Cancel As Integer)
If vbYes = MsgBox("Do you want to send this twirler an email
notification" _
& " of the status of her/his registration?", vbYesNo + 32, "Send
An Email?") Then
Cancel = True
Me.comboTwirler.Undo
End If

I thought the undo was what I was missing but guess not.
 
D

Dirk Goldgar

Steve S said:
That did not seem to work. Here is my code.

Private Sub comboTwirler_BeforeUpdate(Cancel As Integer)
If vbYes = MsgBox("Do you want to send this twirler an email
notification" _
& " of the status of her/his registration?", vbYesNo + 32,
"Send
An Email?") Then
Cancel = True
Me.comboTwirler.Undo
End If

I thought the undo was what I was missing but guess not.

Your code will cancel the combo update (and undo the user's entry) if the
user replies "Yes" to the question. Is that what you had in mind? I
thought you would want to cancel things if the user replied "No".

The code I posted worked fine for me in my test.
 

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