Connecting Tech Pros Worldwide Help | Site Map

Re: oldvalue, combo box, beforeupdate

Allen Browne
Guest
 
Posts: n/a
#1: Nov 19 '08
Testing if the new value is different from the old one avoids giving the
message in these cases:
a) It's a new record (so there was no old value.)
b) No customer was specified previously (so the customer wasn't 'changed'.)
c) No customer is specified now. (You may or may not want to check this.)
d) The record was edited, but the customer wasn't changed (including leaving
it blank as it was before.)

Most of these have to do with handling Nulls. If you want to read further
about considering the 3 possible outcomes for any comparision (True, False,
or Null), see the last error addressed in this article:
Common Errors with Null
at:
http://allenbrowne.com/casu-12.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"franc sutherland" <franc.sutherland@googlemail.comwrote in message
news:ce3acb8f-3c32-4c50-8325-e638096ba287@p35g2000prm.googlegroups.com...
On Nov 15, 2:31 am, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
Quote:
>
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim bWarn As Boolean
>
With Me.Customer_id
If .Value <.OldValue Then
bWarn = True
strMsg = strMsg & "Changed customer from " & .OldValue & " to "
& .Value." & vbCrLf
End If
End With
>
If bWarn And Not Cancel Then
If MsgBox(strMsg, vbOkCancel+vbQuestion, "Confirm change") <vbOk
Then
Cancel = True
Me.Undo
End If
End If
End Sub
Thanks for that. It worked a treat. However, I don't understand why
the code I was using wasn't given the same outcome. Reading it
through, it seems to follow the same logical path. Is the new value
the same as the old value, if not, confirm action and then update or
undo. Can you explain, please?

franc sutherland
Guest
 
Posts: n/a
#2: Nov 19 '08

re: Re: oldvalue, combo box, beforeupdate


On Nov 19, 1:35*pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
Quote:
Testing if the new value is different from the old one avoids giving the
message in these cases:
a) It's a new record (so there was no old value.)
b) No customer was specified previously (so the customer wasn't 'changed'..)
c) No customer is specified now. (You may or may not want to check this.)
d) The record was edited, but the customer wasn't changed (including leaving
it blank as it was before.)
>
Most of these have to do with handling Nulls. If you want to read further
about considering the 3 possible outcomes for any comparision (True, False,
or Null), see the last error addressed in this article:
* * Common Errors with Null
at:
* *http://allenbrowne.com/casu-12.html
>
--
Allen Browne - Microsoft MVP. *Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
>
"franc sutherland" <franc.sutherl...@googlemail.comwrote in message
>
news:ce3acb8f-3c32-4c50-8325-e638096ba287@p35g2000prm.googlegroups.com...
On Nov 15, 2:31 am, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
>
>
>
>
>
Quote:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim bWarn As Boolean
>
Quote:
With Me.Customer_id
If .Value <.OldValue Then
bWarn = True
strMsg = strMsg & "Changed customer from " & .OldValue & " to "
& .Value." & vbCrLf
End If
End With
>
Quote:
If bWarn And Not Cancel Then
If MsgBox(strMsg, vbOkCancel+vbQuestion, "Confirm change") <vbOk
Then
Cancel = True
Me.Undo
End If
End If
End Sub
>
Thanks for that. *It worked a treat. *However, I don't understand why
the code I was using wasn't given the same outcome. *Reading it
through, it seems to follow the same logical path. *Is the new value
the same as the old value, if not, confirm action and then update or
undo. *Can you explain, please?
Thanks Allen.

Much appreciated,

Franc.
Closed Thread