before update not working as I expect

S

SuzyQ

I have this code in a before update event - I don't care whether the user
changes the data or not, I just want to warn the user that the data has been
changed. This code is preventing the user from leaving the field regardless.
Even if I comment out all of the code but leave the procedure - just having
a BeforeUpdate procedure, even an empty one prevents the user from moving on
from the field.

Private Sub Quantity_BeforeUpdate(Cancel As Integer)
If Me.InvenotryItemAdded = True Then
'inventory item already added -
'warn user quantity has changed - user will need to update inventory
manually

If Me.Quantity.Value <> Me.Quantity.OldValue Then
MsgBox Me.Quantity.OldValue & " has already been addded to
inventoy" & vbCrLf & _
"Update inventory manually through inventory form"
End If
End If
Cancel = 0 'accept data entered
End Sub
 
S

SuzyQ

The strange thing is that the code isn't even being executed... I put a break
in the code and it never reached the break. Yes I put the break on the if
not inside it... and it doen't matter whether Me.InvenotryItemAdded is true
of false. When I remove the procedure entirely I can then pass through the
field again, but that's not what I want.
 
K

Ken Snell MVP

Does your actual code contain the spellings that you show here (Invenotry?).
Be sure you have no typos.

This code, as presented, should not prevent the user from leaving the
control, although the user may need to acknowledge the MsgBox first. The
fact that it's not running (breakpoint doesn't trigger) indicates that
something else is causing the problem. Do you have code in the Exit or
LostFocut events that is running as well? Do you have code running in the
form's BeforeUpdate event?
 
M

Marshall Barton

SuzyQ said:
I have this code in a before update event - I don't care whether the user
changes the data or not, I just want to warn the user that the data has been
changed. This code is preventing the user from leaving the field regardless.
Even if I comment out all of the code but leave the procedure - just having
a BeforeUpdate procedure, even an empty one prevents the user from moving on
from the field.

Private Sub Quantity_BeforeUpdate(Cancel As Integer)
If Me.InvenotryItemAdded = True Then
'inventory item already added -
'warn user quantity has changed - user will need to update inventory
manually

If Me.Quantity.Value <> Me.Quantity.OldValue Then
MsgBox Me.Quantity.OldValue & " has already been addded to
inventoy" & vbCrLf & _
"Update inventory manually through inventory form"
End If
End If
Cancel = 0 'accept data entered
End Sub


Commenting the code not having any effect is an indicator of
a code corruption problem. Try selecting all the code in
the form's module (not just the one procedure) and then
using Copy to put it in the Clipboard. Then set the form's
HasModule property to No. Use the View - Code menu item to
create a new empty module and Paste the code from the
Clipboard back into the new module.

Use the Debug - Compile menu item to check for compile
errors and, if there are no errors, compile the code.

NOTE: If the problem was corruption, it was most likely
caused by editing the code in the module while the form was
displayed in form view. Try really, really hard to remember
to ALWAYS switch to design view before touching the form's
module.
 
S

SuzyQ

I do have code in the form's before update. I can't paste if for you now
because I've left for the day and won't be back until monday. But if the
specific code in the form's before update matters, let me know and I'll post
it monday. Yes the spellings are correct - I copied/pasted to be sure.

I don't want the user to be prevented from moving beyond the field, so it is
written the way I want it to work, just wondering why it's not working. If
you have suggestions, let me know and I'll try them on Monday. I don't have
any exit or lost focus events
 
S

SuzyQ

Then it is probably corruption because I did ACCIDENTLY edit code while it
was in form view. I generally try not to do that, but didn't realize the the
code was still running at the time. I will do as you suggest, but can't try
until Monday. I'll let you know if it worked. Thanks!!
 
S

SuzyQ

It was corruption. Thanks for the insight. I will pay much closer attention
to editing code from now on.
 

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