473,503 Members | 3,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A2K: problem with limitfieldsize code that restricts number of input characters

I use this code from http://support.microsoft.com/kb/210047 to stop more
than 50 characters being input into a textbox.

****code start****
Sub LimitFieldSize (KeyAscii, MAXLENGTH)
Dim C As Control
Dim CLen As Integer

Set C = Screen.ActiveControl

' Exit if a non-printable character is typed.
If KeyAscii < 32 Then Exit Sub

' Exit if typing replaces a selection.
If C.SelLength 0 Then Exit Sub

' Fetch length of current contents + 1 for the character typed.
CLen = Len(C.Text & "") + 1

' Are there trailing spaces to contend with?
If C.SelStart + 1 CLen Then CLen = C.SelStart + 1

' Is length of string greater than max?
If CLen MAXLENGTH Then
Beep
KeyAscii = 0
End If
End Sub
****code end****
The problem is that once the limit is reached the count stays at 50 even
after the user deletes a few characters and then tries to enter something
different. This means the caret aka cursor, just stays locked and no more
input is allowed.

I have been trying to rewrite the code without success - can anyone see what
needs doing to make this code work in the above situation?

thanks

Feb 8 '08 #1
3 1950
"Deano" <de***@mailinator.comwrote in message
news:61*************@mid.individual.net...
>I use this code from http://support.microsoft.com/kb/210047 to stop more
than 50 characters being input into a textbox. [snip]
The problem is that once the limit is reached the count stays at 50 even
after the user deletes a few characters ...
Haven't fooled with that particular solution, but here's an alternative:
Unbound text box: limiting entry length
at:
http://allenbrowne.com/ser-34.html

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

Feb 8 '08 #2

"Allen Browne" <Al*********@SeeSig.Invalidwrote in message
news:47**********************@per-qv1-newsreader-01.iinet.net.au...
"Deano" <de***@mailinator.comwrote in message
news:61*************@mid.individual.net...
I use this code from http://support.microsoft.com/kb/210047 to stop more
than 50 characters being input into a textbox. [snip]
The problem is that once the limit is reached the count stays at 50 even
after the user deletes a few characters ...

Haven't fooled with that particular solution, but here's an alternative:
Unbound text box: limiting entry length
at:
http://allenbrowne.com/ser-34.html
I might use that where I can, but I'm mostly using bound textboxes.
Feb 8 '08 #3
Deano wrote:
I use this code from http://support.microsoft.com/kb/210047 to stop more
than 50 characters being input into a textbox.

****code start****
Sub LimitFieldSize (KeyAscii, MAXLENGTH)
Dim C As Control
Dim CLen As Integer

Set C = Screen.ActiveControl

' Exit if a non-printable character is typed.
If KeyAscii < 32 Then Exit Sub

' Exit if typing replaces a selection.
If C.SelLength 0 Then Exit Sub

' Fetch length of current contents + 1 for the character typed.
CLen = Len(C.Text & "") + 1

' Are there trailing spaces to contend with?
If C.SelStart + 1 CLen Then CLen = C.SelStart + 1

' Is length of string greater than max?
If CLen MAXLENGTH Then
Beep
KeyAscii = 0
End If
End Sub
****code end****
The problem is that once the limit is reached the count stays at 50 even
after the user deletes a few characters and then tries to enter something
different. This means the caret aka cursor, just stays locked and no more
input is allowed.

I have been trying to rewrite the code without success - can anyone see what
needs doing to make this code work in the above situation?

thanks
What happens if you remove the
KeyAscii = 0
line? It seems you are setting it to null (guess I need a Ascii chart).
What would happen if you set KeyAscii to a space (32).

Lava
http://www.youtube.com/watch?v=TNJJSYC4zWM
Feb 8 '08 #4

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

Similar topics

4
2061
by: Kim14 | last post by:
I have a table that works fine in IE, but doesn't work in Netscape or Firefox. It should automatically come up with numbers in some of the fields and depending what is entered, it should calculate...
1
3170
by: Richard Holliingsworth | last post by:
Hello: Thanks for your quick response. I'm trying to import a new Excel file into an A2K table and it's truncating the data. One of the Excel columns is a text field that can be up to 2000...
0
3910
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
10
1648
by: Arno R | last post by:
Hi all, I have a database that I need to use in different versions of Access. This is A97 in most places and A2k in a few other locations. (I develop in A97 and convert the db to A2k for these...
13
1541
by: vasudevmukherjee | last post by:
Hi! Can somebody help tell me why the following code gives a garbage value while producing first student's name, whereas it gives the names correctly for other three students - I really fail to...
1
4132
by: Little | last post by:
Could someone help me figure out how to put my project together. I can't get my mind wrapped around the creation of the 4 double Linked Lists. Thank your for your insight. 1. Create 4 double...
2
1928
by: Cerebral Believer | last post by:
Hi folks, Can anyone help me with this form: http://futurebydesign-music.com/_member/club_fbd_reg.php I have followed to coding instructions aas closely as I can, but I am getting errors...
7
1986
by: dtschoepe | last post by:
Hi, I am working on a project for school and I am trying to get my head around something weird. I have a function setup which is used to get an input from stdin and a piece of memory is created...
1
2523
by: biznitchil | last post by:
it is a bit jacked up, but copy and paste it into an IDE(i use jGRASP) plz help me...it worked just fine before I added the menu..you can e-mail me if you have any <Removed> import java.util.*; ...
0
7188
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
7063
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
7313
jinu1996
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...
1
6970
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...
0
5558
agi2029
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,...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
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...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.