473,569 Members | 2,764 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.ActiveCo ntrol

' 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 1952
"Deano" <de***@mailinat or.comwrote in message
news:61******** *****@mid.indiv idual.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*********@Se eSig.Invalidwro te in message
news:47******** **************@ per-qv1-newsreader-01.iinet.net.au ...
"Deano" <de***@mailinat or.comwrote in message
news:61******** *****@mid.indiv idual.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.ActiveCo ntrol

' 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
2067
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 and come up with a dollar amount. If anyone out there sees what I am doing wrong- could you offer some advice? I apologize in advance for...
1
3191
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 characters. When I import it into A2K, that field is truncated. If I try to inport the file into an EXISTING table that I define myself where that...
0
3921
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header,...
10
1655
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 other locations) FYI: I am using A97 as backend for both versions. No problem. After conversion A97 > A2k everything (seems to) work(s) just fine,...
13
1543
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 understand since it is not generating the required results.- Thank you in anticipation - Vasudev. #include <stdio.h> main () { char student, *x;
1
4142
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 linked lists as follows: (a) A double linked list called NAMES which will contain all C like identifiers of less than 256 characters long...
2
1937
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 about not filling in all the fields on the form correctly when I test it. Is validating a form with radio buttons difficult?
7
1994
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 on the heap using malloc. This input is then run through a regex and another test. The result is passed back as a char pointer to the program for...
1
2528
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.*; public class VowelsConsCounter { public int i= list.indexOf(object); public static char getMenuSelection(); { String input; ...
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7921
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, 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. ...
1
7666
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...
0
7964
tracyyun
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...
0
6278
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
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...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.