Solved

MaxLength

Posted on 2002-04-16
5
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

707 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