Solved

MaxLength

Posted on 2002-04-16
5
302 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
Comment Utility
just set  MaxLength propery for textbox, in this case you can't type more chars then maxlength.
0
 
LVL 5

Expert Comment

by:rkot2000
Comment Utility
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
Comment Utility
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
Comment Utility
you could alway increase the field lenght in the database
0
 

Author Comment

by:ADawn
Comment Utility
Good Suggestions - Thanks, ADawn
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now