473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How best to modify value entered into textbox on form during BeforeUpdate event code?

MLH
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
the 17-char value entered easily enough, but I cannot seem
to replace that which was entered with a new value that has
replaced Oh's with zeros. I get a 2115 error complaining that
"The FN set to the BeforeUpdate property is preventing Access
from saving data in the field".

I have tried a line DoCmd.CancelEvent before attempting to
replace the bad data with good data but this error won't let
me proceed. How can I do this?
Feb 5 '06 #1
6 4191
MLH wrote:
I would like
to change it to a zero during the BeforeUpdate code.


I have similar requirements sometimes. There may be a way to do this
with the before update event and the text property of the text box, but
I've had great difficulty changing the text property in this event.

What I do is use a replace function in the after update event (as well
as using the UCASE or LCASE function if you don't want mixed cases). On
the mvps org site, there's a Terry Kreft (I believe) function called
something like "changestr" which has very reliably performed the replace
function (available on A2000 and later).

I think working with the after update event for changing data values
will be less of a headache for you - it lowered by aspirin intake,
anyway! 8)
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Feb 5 '06 #2
MLH
Searching for changestr on the mvp's site didn't
result in a hit - could it be something else?
Feb 5 '06 #3
MLH
For now, I think I'll use the KeyDown event to trap 'n prevent
Oh's from being typed. Although I'd rather handle it behind the
scenes for my users, this is the only thing I can get to work at
this time.

Private Sub SerialNum_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo ErrorSerialNum_KeyDown
Dim ThisForm As String
ThisForm = Me.Name

If KeyCode = 111 Or KeyCode = 79 Then
DoCmd.CancelEvent
MyString = "VIN codes are alpha-numeric codes that sometimes
contain zeros but NEVER contain Oh's. I'm "
MyString = MyString & "talking about the letter 'O'. So, please
continue typing in your VIN number but "
MyString = MyString & "refrain from typing O's (Oh's) in your
code. Type a zero instead."
MsgBox MyString, vbInformation, "No Oh's Allowed! - " & MyApp$ &
", rev. " & MY_VERSION$
End If

ExitSerialNum_KeyDown:
Exit Sub

ErrorSerialNum_KeyDown:
Dim r As String, k As String, Message3 As String
r = "The following unexpected error occurred in Sub
SerialNum_KeyDown, CBF on " & ThisForm & "."
k = CRLF & CRLF & str$(Err) & ": " & Quote & Error$ & Quote
Message3 = r & k
MsgBox Message3, vbExclamation, "Unexpected Error - " & MyApp$ &
", rev. " & MY_VERSION$
Resume ExitSerialNum_KeyDown

End Sub

Feb 5 '06 #4

"MLH" <CR**@NorthState.net> wrote in message
news:4r********************************@4ax.com...
For now, I think I'll use the KeyDown event to trap 'n prevent
Oh's from being typed. Although I'd rather handle it behind the
scenes for my users, this is the only thing I can get to work at
this time.

Private Sub SerialNum_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo ErrorSerialNum_KeyDown
Dim ThisForm As String
ThisForm = Me.Name

If KeyCode = 111 Or KeyCode = 79 Then
DoCmd.CancelEvent
MyString = "VIN codes are alpha-numeric codes that sometimes
contain zeros but NEVER contain Oh's. I'm "
MyString = MyString & "talking about the letter 'O'. So, please
continue typing in your VIN number but "
MyString = MyString & "refrain from typing O's (Oh's) in your
code. Type a zero instead."
MsgBox MyString, vbInformation, "No Oh's Allowed! - " & MyApp$ &
", rev. " & MY_VERSION$
End If

ExitSerialNum_KeyDown:
Exit Sub

ErrorSerialNum_KeyDown:
Dim r As String, k As String, Message3 As String
r = "The following unexpected error occurred in Sub
SerialNum_KeyDown, CBF on " & ThisForm & "."
k = CRLF & CRLF & str$(Err) & ": " & Quote & Error$ & Quote
Message3 = r & k
MsgBox Message3, vbExclamation, "Unexpected Error - " & MyApp$ &
", rev. " & MY_VERSION$
Resume ExitSerialNum_KeyDown

End Sub

You can intercept this and automatically correct it if you feel this is the
correct policy. It might appear weird to your users that they press the
keyboard button for one thing, but another thing appears on the screen. But
anyway:

Private Sub SerialNum_KeyPress(KeyAscii As Integer)
If KeyAscii = 111 Or KeyAscii = 79 Then
KeyAscii = 48
End If
End Sub
Having said that, I use this technique for postcode/zipcode fields so that
you can only enter in upper case:

Private Sub txtTest_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
Feb 6 '06 #5
MLH wrote:
Searching for changestr on the mvp's site didn't
result in a hit - could it be something else?


That's bizarre, I can't seem to find the one I'm used to there,
either... However, there is a find and replace by Aldon Streeter at
http://www.mvps.org/access/strings/str0004.htm that looks like it'll do
fine. But the one I'm used to is a bit different and wasn't written by
Aldon. It must have changed since I took it from the Access Web.
However, the function in the URL I've provided looks pretty similar and
should work just fine for your purposes.

The other approach Anthony has mentioned looks good too, but I think
having a user's entry change after s/he's left the text box might be
less confusing (as per Anthony's caution) but maybe not. 8)
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Feb 6 '06 #6
MLH
Hey, I like both of those, Anthony.

Thx!
Feb 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
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...
11
by: David Messner | last post by:
Ok I know this is simple but the statement eludes me... I have a date field where I want the default value on the data entry form's date field to be the last date entered. I figure I can do this...
2
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...
2
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...
10
by: MLH | last post by:
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...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
2
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...
5
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...
5
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
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...
0
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
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.