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? 10 2267
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?
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
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?
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
>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.
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.
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
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.
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gene |
last post by:
When entering a record in a form, I would like a value in a field of
the previous record to be entered automatically into a different field
of the current record. Which way should I go? Is it also...
|
by: Terry Bickle |
last post by:
Please forgive me for using the wrong term here or there. I'm an old Excel 4
macro guy who didn't convert to VB and I'm tinkering with an Access 2000 DB.
I'm sure there is a simple Access 101...
|
by: Mark |
last post by:
I am attempting to populate several textbox controls
from VBA code. With each attempt, I get the following
error:
"The macro or function set to the BeforeUpdate or
ValidationRule property for...
|
by: PC Datasheet |
last post by:
In a form/subform I have an unbound combobox in the form header that sets
the value of a field in the subform so that it does not have to be entered
for each record. In the BeforeUpdate event of...
|
by: Xaviero |
last post by:
I have a textbox in my editItemTemplate within my datagrid. This textbox's autoPostback property is true, so I can do some verfications before the user moves on to the next textbox. My verification...
|
by: MLH |
last post by:
Using A97.
Want to examine 17-char VIN entered by user. VIN codes
are alphanumeric and do not contain Oh's to prevent the
confusion that could result if zeros were misread as O's
or o's. So, if...
|
by: deancarstens |
last post by:
Hi,
I'm a novice with VB and I've written this pretty simple script, but
for the life of me, I can't get the last bit of the script to work. It
should compare the value entered by the user...
|
by: ApexData |
last post by:
I have a bound textbox called txtMyBox with the current string value
of "200".
Once the user enters the textbox, and while the user is still in the
textbox, I would like to check the changed value...
|
by: vsteshenko |
last post by:
Hello,
This is my second post to the any usernet group and the first one was
posted to the wrong one.
I am currently working on creating an order form for sales associates
at my work to be used...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |