Updating TEXT or VALUE in BeforeUpdate sub not posible?

  • Thread starter Thread starter Rob Hofkens
  • Start date Start date
R

Rob Hofkens

Hello everyone :)

I have a textbox with a BeforeUpdate procedure that has some code to
validate the entered data.
When the validation fails I set Cansel to True.
But when it's valid I would like to change the entered data and store it in
the textbox value (or text) property.
This result in an error 2115 though :(
I go arround this problem by changing the data in the AfterUpdate sub but I
wonder why it doesn't work ?

Little sample just to show you what I mean:

Private Sub Sample_BeforeUpdate(Cancel As Integer)
If IsNumeric(Sample.Text) Then
Me.Sample.Value = Me.Sample.Text * 2
Else
Cancel = True
End If
End Sub


Rob.
 
Rob

Here's the logic of the situation, at least as I see it:

1. Accept this value
2. Before you accept it, multiply it by 2
3. Accept the new value
4. But before you do, * 2
5. ...(repeat until dizzy)

By using the AfterUpdate to multiply by 2, you let the BeforeUpdate handle
validation and preserve the original value.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Sorry I don't understand your explaination?
Does it mean that my work arround with the AfterUpdate sub is the right way
to do it ?
Or can it be done in the BeforeUpdate ?

Rob.
 
Rob

If you try to do it BeforeUpdate, my explanation shows what Access is trying
to do (it has to save it, but before it does, it has to update it, but
before it does, ...).

Use the AfterUpdate.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

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

Back
Top