By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,661 Members | 1,808 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,661 IT Pros & Developers. It's quick & easy.

A97 - easiest way to have a look at a value entered into a textbox during the BeforeUpdate event?

P: n/a
MLH
Would like to examine the value entered into a textbox
on an A97 form during the BeforeUpdate event. The
textbox may or may not have had an earlier entry in it
prior to the latest value that is now in the process of
being entered. What's the best way to refer to the
value just typed that is about to update the textbox?
Nov 13 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Just use the Value. That's the default property, so you can just code like
this:

Private Sub BirthDate_BeforeUpdate(Cancel As Integer)
If Me.BirthDate > Date Then
Cancel = True
MsgBox "Born in the future?" & vbCrLf & _
"Correct the entry, or press <Esc> to undo."
End If
End Sub

--
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.

"MLH" <CR**@NorthState.net> wrote in message
news:08********************************@4ax.com...
Would like to examine the value entered into a textbox
on an A97 form during the BeforeUpdate event. The
textbox may or may not have had an earlier entry in it
prior to the latest value that is now in the process of
being entered. What's the best way to refer to the
value just typed that is about to update the textbox?

Nov 13 '05 #2

P: n/a
MLH
I don't know why I thought it wouldn't be there
until AfterUpdate event. Bonkers, I guess. Will
try now.
xxxxxxxxxxxxxxxxxxxxxxxxxxx
Just use the Value. That's the default property, so you can just code like
this:

Private Sub BirthDate_BeforeUpdate(Cancel As Integer)
If Me.BirthDate > Date Then
Cancel = True
MsgBox "Born in the future?" & vbCrLf & _
"Correct the entry, or press <Esc> to undo."
End If
End Sub


Nov 13 '05 #3

P: n/a
MLH
On Tue, 01 Nov 2005 11:39:21 -0500, MLH <CR**@NorthState.net> wrote:
I don't know why I thought it wouldn't be there
until AfterUpdate event. Bonkers, I guess. Will
try now.
xxxxxxxxxxxxxxxxxxxxxxxxxxx

Well, of course. You were right. Just out of curiousity, where
does the prior value go (1) and how might IT be accessed during
that same BeforeUpdate event (2)? I tried out this little snippet...

Private Sub Text0_BeforeUpdate(Cancel As Integer)
MsgBox Text0
Dim Response As Integer
Response = MsgBox("Wanna replace the value?", vbYesNo, "Answer?")
If Response = vbYes Then
Exit Sub
Else
DoCmd.CancelEvent
SendKeys ("{esc}")
End If
End Sub

Say someone has entered "Red" into Text0 control. Its sitting
there, displaying "Red" and you come along and type "Blue"
into it and press Enter-key. The msgbox Statement displays.
Sure enough, you see "Blue" in the box. But after clicking
OK, the msgbox Function prompts you for a choice. You must
accept or reject the new entry of "Blue". If you click Yes - the
procedure ends and the textbox now displays "Blue". But if
you click No, "Blue" is discarded and "Red" returns. Where
did "Red" go temporarily and can I read THAT VALUE from
within the BeforeUpdate code as well?

Nov 13 '05 #4

P: n/a
On Tue, 01 Nov 2005 11:57:32 -0500, MLH <CR**@NorthState.net> wrote:
On Tue, 01 Nov 2005 11:39:21 -0500, MLH <CR**@NorthState.net> wrote:
I don't know why I thought it wouldn't be there
until AfterUpdate event. Bonkers, I guess. Will
try now.
xxxxxxxxxxxxxxxxxxxxxxxxxxx

Well, of course. You were right. Just out of curiousity, where
does the prior value go (1) and how might IT be accessed during
that same BeforeUpdate event (2)? I tried out this little snippet...

Private Sub Text0_BeforeUpdate(Cancel As Integer)
MsgBox Text0
Dim Response As Integer
Response = MsgBox("Wanna replace the value?", vbYesNo, "Answer?")
If Response = vbYes Then
Exit Sub
Else
DoCmd.CancelEvent
SendKeys ("{esc}")
End If
End Sub

Say someone has entered "Red" into Text0 control. Its sitting
there, displaying "Red" and you come along and type "Blue"
into it and press Enter-key. The msgbox Statement displays.
Sure enough, you see "Blue" in the box. But after clicking
OK, the msgbox Function prompts you for a choice. You must
accept or reject the new entry of "Blue". If you click Yes - the
procedure ends and the textbox now displays "Blue". But if
you click No, "Blue" is discarded and "Red" returns. Where
did "Red" go temporarily and can I read THAT VALUE from
within the BeforeUpdate code as well?


Me.Text0.OldValue
Nov 13 '05 #5

P: n/a
MLH
>Me.Text0.OldValue
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hmmm??? I tried that, but it didn't seem to work for me...

Private Sub Text0_BeforeUpdate(Cancel As Integer)
Dim Response As Integer
Response = MsgBox("Wanna replace the old value (" & Me.Text0.OldValue
& ") with " & Me.Text0 & "?", vbYesNo, "Answer?")
If Response = vbYes Then
Exit Sub
Else
DoCmd.CancelEvent
SendKeys ("{esc}")
End If
End Sub

If "Yellow" exists in the control and I change the value to "Orange",
the code above asks me "... if I want to change the oldvalue (Orange)
with Orange?" If my response is Yes, Orange is displayed in the
textbox. If my answer is No, Yellow is displayed. The oldvalue
property doesn't seem to be the "old value" quite yet. Seems
logical, as the Update has NOT yet occurred.
Nov 13 '05 #6

P: n/a
Wayne is correct: the OldValue property is where you will find the previous
value of the field.

Unbound controls don't have an OldValue, so perpaps your control is unbound?

BTW, if you did want to read exactly what the user put in the control, you
could read its Text property while it still has focus. This example shows
how to test if a percent sign was typed into a field, and if not it divides
by 100 (i.e. if the user types just 10, they get 10% not 1000%):

Private Sub TaxRate_AfterUpdate()
With Me.TaxRate
If Not IsNull(.Value) Then
If InStr(.Text, "%") = 0 Then
.Value = .Value / 100
End If
End If
End With
End Sub

--
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.

"MLH" <CR**@NorthState.net> wrote in message
news:p5********************************@4ax.com...
Me.Text0.OldValue

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hmmm??? I tried that, but it didn't seem to work for me...

Private Sub Text0_BeforeUpdate(Cancel As Integer)
Dim Response As Integer
Response = MsgBox("Wanna replace the old value (" & Me.Text0.OldValue
& ") with " & Me.Text0 & "?", vbYesNo, "Answer?")
If Response = vbYes Then
Exit Sub
Else
DoCmd.CancelEvent
SendKeys ("{esc}")
End If
End Sub

If "Yellow" exists in the control and I change the value to "Orange",
the code above asks me "... if I want to change the oldvalue (Orange)
with Orange?" If my response is Yes, Orange is displayed in the
textbox. If my answer is No, Yellow is displayed. The oldvalue
property doesn't seem to be the "old value" quite yet. Seems
logical, as the Update has NOT yet occurred.

Nov 13 '05 #7

P: n/a
MLH
Allen Brown made the point that your suggestion to
use OldValue property would not work for me if the
control I was using it on was an unbound control.
Wouldn't you know it? It is. So I'm back to square
one. It seems there would be a way to have a peek
at what was there. It really does. Access does not
forget it, that much is certain. If the update is halted
with a cancelevent method during BeforeUpdate
event procedure code, Access puts the initial value
back into the control - aborting the update. So it is
certainly saved somewhere.

Me.Text0.OldValue


Nov 13 '05 #8

P: n/a
MLH
On Wed, 2 Nov 2005 08:38:48 +0800, "Allen Browne"
<Al*********@SeeSig.Invalid> wrote:
Wayne is correct: the OldValue property is where you will find the previous
value of the field.

Unbound controls don't have an OldValue, so perpaps your control is unbound? You are absolutely right. Its an unbound control on a form named
frmAOCCVM100ProcessingForm. The control name is CourtCaseNum, and it
is most certainly unbound.

BTW, if you did want to read exactly what the user put in the control, you
could read its Text property while it still has focus. This example shows
how to test if a percent sign was typed into a field, and if not it divides
by 100 (i.e. if the user types just 10, they get 10% not 1000%):

Private Sub TaxRate_AfterUpdate()
With Me.TaxRate
If Not IsNull(.Value) Then
If InStr(.Text, "%") = 0 Then
.Value = .Value / 100
End If
End If
End With
End Sub

I may just be able to make use of this. Let me give it some thought.
Am still trying to read what what "there" prior to typing something
else over what WAS there. I'm sure the value is not lost - but unsure
as to how to read it from BeforeUpdate event procedure code.

Nov 13 '05 #9

P: n/a
On Tue, 01 Nov 2005 20:41:59 -0500, MLH <CR**@NorthState.net> wrote:
Allen Brown made the point that your suggestion to
use OldValue property would not work for me if the
control I was using it on was an unbound control.
Wouldn't you know it? It is. So I'm back to square
one. It seems there would be a way to have a peek
at what was there. It really does. Access does not
forget it, that much is certain. If the update is halted
with a cancelevent method during BeforeUpdate
event procedure code, Access puts the initial value
back into the control - aborting the update. So it is
certainly saved somewhere.

Me.Text0.OldValue


Create a variable (variant) in the declarations section at the top of your form module.

Dim varOldValue as Variant

Set this variable in the Enter event of the control to the current value of the control.

Sub Text0_Enter()
varOldValue = Me.Text0
End Sub

Use this variable in your BeforeUpdate code

Private Sub Text0_BeforeUpdate(Cancel As Integer)
Dim Response As Integer
Response = MsgBox("Wanna replace the old value (" & varOldValue
& ") with " & Me.Text0 & "?", vbYesNo, "Answer?")
If Response = vbYes Then
Exit Sub
Else
DoCmd.CancelEvent
Me.Text0.Undo
End If
End Sub
Nov 13 '05 #10

P: n/a
MLH
By golly, that sounds like it will work! Here I am looking my butt off
for a built-in function that does this - when a little creativity and
a few lines of code take care of it perfectly well.

Thx Wayne!
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Create a variable (variant) in the declarations section at the top of your form module.

Dim varOldValue as Variant

Set this variable in the Enter event of the control to the current value of the control.

Sub Text0_Enter()
varOldValue = Me.Text0
End Sub

Use this variable in your BeforeUpdate code

Private Sub Text0_BeforeUpdate(Cancel As Integer)
Dim Response As Integer
Response = MsgBox("Wanna replace the old value (" & varOldValue
& ") with " & Me.Text0 & "?", vbYesNo, "Answer?")
If Response = vbYes Then
Exit Sub
Else
DoCmd.CancelEvent
Me.Text0.Undo
End If
End Sub


Nov 13 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.