Before update, after update or change event? or does it matter?

C

Chris K

Couple questions

I use bound dropdown list for quite comprehensive display of future booking
dates including how many are already booked on those dates and same combo to
choose booking date for the client record - the problem is I need to guard
against them changing dates by accident when they're using the dropdown just
to look at future bookings

Private Sub Booked_AfterUpdate()
With Me.Booked
If Not IsNull(.OldValue) And .Value <> .OldValue Then _
If MsgBox("Change " & .OldValue & " to " & .Value & "?",
vbYesNo) = vbNo Then .Value = .OldValue
End With
End Sub

Works fine but my questions are

1/ Should I use before update, after update or change event? or does it
matter?

2/ Why wont it let me 'Undo' e.g.

If MsgBox("Change " & .OldValue & " to " & .Value & "?", vbYesNo) = vbNo
Then .Undo 'It doesn't 'undo' the changes no matter which event i use?
hence I used .Value = .OldValue
 
M

Marshall Barton

Chris said:
I use bound dropdown list for quite comprehensive display of future booking
dates including how many are already booked on those dates and same combo to
choose booking date for the client record - the problem is I need to guard
against them changing dates by accident when they're using the dropdown just
to look at future bookings

Private Sub Booked_AfterUpdate()
With Me.Booked
If Not IsNull(.OldValue) And .Value <> .OldValue Then _
If MsgBox("Change " & .OldValue & " to " & .Value & "?",
vbYesNo) = vbNo Then .Value = .OldValue
End With
End Sub

Works fine but my questions are

1/ Should I use before update, after update or change event? or does it
matter?

Not the Change event, it fires for every keystroke.

I would use the before BeforeUpdate event:
If Not IsNull(.OldValue) And .Value <> .OldValue Then
If MsgBox("Change " & .OldValue & " to " & .Value &
"?", vbYesNo) = vbNo Then
Cancel = True
.Undo
End If
End If

But, I don't have a strong objection to your code in the
AfterUpdate event.
2/ Why wont it let me 'Undo' e.g.

If MsgBox("Change " & .OldValue & " to " & .Value & "?", vbYesNo) = vbNo
Then .Undo 'It doesn't 'undo' the changes no matter which event i use?
hence I used .Value = .OldValue

I don't see why you are having a problem with Undo unless
you have a procedure named Undo in the form's module.
 

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