Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MaxLength

Posted on 2002-04-16
5
Medium Priority
?
324 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 40 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
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…
Suggested Courses

618 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