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 2299
Just use the Value. That's the default property, so you can just code like
this:
Private Sub BirthDate_Befor eUpdate(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**@NorthStat e.net> wrote in message
news:08******** *************** *********@4ax.c om... 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.
xxxxxxxxxxxxxxx xxxxxxxxxxxx Just use the Value. That's the default property, so you can just code like this:
Private Sub BirthDate_Befor eUpdate(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**@NorthStat e.net> wrote: I don't know why I thought it wouldn't be there until AfterUpdate event. Bonkers, I guess. Will try now. xxxxxxxxxxxxxx xxxxxxxxxxxxx
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_BeforeUpd ate(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.CancelEve nt
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**@NorthStat e.net> wrote: On Tue, 01 Nov 2005 11:39:21 -0500, MLH <CR**@NorthStat e.net> wrote:
I don't know why I thought it wouldn't be there until AfterUpdate event. Bonkers, I guess. Will try now. xxxxxxxxxxxxx xxxxxxxxxxxxxx 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_BeforeUpd ate(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.CancelEve nt 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.OldVal ue
>Me.Text0.OldVa lue
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx x
Hmmm??? I tried that, but it didn't seem to work for me...
Private Sub Text0_BeforeUpd ate(Cancel As Integer)
Dim Response As Integer
Response = MsgBox("Wanna replace the old value (" & Me.Text0.OldVal ue
& ") with " & Me.Text0 & "?", vbYesNo, "Answer?")
If Response = vbYes Then
Exit Sub
Else
DoCmd.CancelEve nt
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_AfterUp date()
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**@NorthStat e.net> wrote in message
news:p5******** *************** *********@4ax.c om... Me.Text0.OldVa lue xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx x Hmmm??? I tried that, but it didn't seem to work for me...
Private Sub Text0_BeforeUpd ate(Cancel As Integer) Dim Response As Integer Response = MsgBox("Wanna replace the old value (" & Me.Text0.OldVal ue & ") with " & Me.Text0 & "?", vbYesNo, "Answer?") If Response = vbYes Then Exit Sub Else DoCmd.CancelEve nt 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.OldVa lue
On Wed, 2 Nov 2005 08:38:48 +0800, "Allen Browne"
<Al*********@Se eSig.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
frmAOCCVM100Pro cessingForm. 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_AfterUp date() 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**@NorthStat e.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.OldV alue
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_BeforeUpd ate(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.CancelEve nt
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 possible to
do this based on criteria from the previous record?
|
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 answer for this.
I have a subform which the user selects an item description from a combo box
from a table. I want to obtain the cost for the item (another field in the
table) also. I've been able to produce the second data field by rewriting
the...
|
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 this field is preventing
Microsoft Acess from saving the data in the field."
Naturally, I have no BeforeUpdate events or
validation rules defined for these fields. If I set
|
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 the combobox I have some code
to check the value against some criteria and if the new selected value fails
the criteria, I cancel the BeforeUpdate event. I need the combobox to return
to its previous value. For example, the current value is MyValue...
|
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 is in the datagrid_Load event handler.
My problem is that every time i get to the datagrid_load after the user has entered a value, the textbox value is empty.
Here are a few more details about my datagrid:
-It is contained in a usercontrol....
| |
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 a user types a 17-char VIN into the textbox
that has an Oh in it (lower or upper case) - I would like
to change it to a zero during the BeforeUpdate code.
So far, I've not been able to accomplish this. I can examine
|
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 under the BeforeUpdate
event and compare it to the value in the main form. It's doing that
just okay, but when I want to reset the value using the original value
(from the main form), it seems the BeforeUpdate event prevents me from
changing it...
|
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 using a function to
see if this changed value exists in a table. If it does, I want do
give a Msgbox Warning and restore the original value.
I thought that I would require the OnUpdate property of the textbox to
do this, but I can't seem t...
|
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 at conventions. I have a main form with two
subforms. On the main form, there is a text box that displays the sum
of total orders entered in the subform, . I'm trying to
create another text box on the main form, that looks at the
subtotal...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |