PDA

Click to See Complete Forum and Search --> : dbgrid limit text input length?


softwareguy74
Aug 24th, 2000, 11:26 AM
How do you limit the length of text the user enteres into a row in a dbgrid?

The problem I'm having is that the particular field that a column in the dbgrid is attached to in my database has a length of 50. If the user enteres more than that in the dbgrid, is just says "Errors Occured". What I want to do is simply prevent the user from entering more than 50 characters so that when the user hits 50, it simply does not allow him to type any more characters..

Any help would be appreciated..

dan

JHausmann
Aug 24th, 2000, 11:37 AM
In the keypress event, check the length of the field. If it's larger than 50, pop an error message.

if len(dbgrid.text) > 50 then
dbgrid.text = left(dbgrid.text,50)
msgbox "the field cannot contain more than 50 characters"
end if


_OR_

if len(dbgrid.text) > 50 then
KeyAscii = 0 ' invalidate the last keystroke (although you should check for a backspace
msgbox "the field cannot contain more than 50 characters"
end if



[Edited by JHausmann on 08-24-2000 at 12:41 PM]