Results 1 to 2 of 2

Thread: dbgrid limit text input length?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    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

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    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]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width