Solved

MaxLength

Posted on 2002-04-16
5
306 Views
Last Modified: 2010-05-02
Hello All,

I want my VB program to limit the number of charactors a user enters into a field (LName) being saved to the database. I guess I would setup a Public constant:

(Public Const con_LName As Integer = 5)

On Save....

If Me.LName.MaxLength > con_LName then
  do something (Trim) with the length of text.(What?).
End IF

OR

On Change....

If Me.LName.MaxLength > con_LName then
     Beep
Exit Sub
End IF



I want to do this because each time a try to save a record that one of the fields are longer than the database will allow, I receive an error message.

Is there a better way of doing this check, then fix?

ADawn

0
Comment
Question by:ADawn
  • 3
5 Comments
 
LVL 5

Expert Comment

by:rkot2000
ID: 6944919
just set  MaxLength propery for textbox, in this case you can't type more chars then maxlength.
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6944928
in some programs i am setting maxlen dynamicly like this during form_load event
for varchar fields :

textbox1.MaxLength = rs.fields(myfield).definedsize
0
 
LVL 5

Accepted Solution

by:
rkot2000 earned 10 total points
ID: 6944937
or you can use your solution :

If Me.LName.MaxLength > con_LName then
 dim s as string
 s=left(me.LName.Text, con_LName)
 'do something with s

End IF
0
 
LVL 1

Expert Comment

by:TechJD
ID: 6946023
you could alway increase the field lenght in the database
0
 

Author Comment

by:ADawn
ID: 6947761
Good Suggestions - Thanks, ADawn
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question