Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Grid Field Lengfth

Status
Not open for further replies.

judyscofield

Programmer
Sep 24, 2001
56
0
0
US
I have a data grid bound to a sql table. If the field length of one of the fields is 25, how do I limit the input in the grid to 25 characters?

Judy
 
You need to capture it in the Grid's KeyPress event:

Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
With DataGrid1
If .col = 3 Then
If KeyCode <> vbKeyBack And .SelLength = 0 Then
If Len(.Columns(3).Text) >= 2 Then KeyCode = 0
End If
End If
End With
End Sub
 
Thanks, this is much better than check the length at .beforeupdate and giving a message.
 

Now, you will find that it will not work when pasting data into a cell. There is a solution for that as well...

I also noted that you have started 30 threads and have not responded to several of them.

Please do this as it is important in this share forum to acknowleded helpful or expert posts and also that others who stumble upon the thread in search for an answer to a similar problem which they are having, know that the solutions, and which solution, actually worked.

Not only that, but you may receive more help to your problems when people see that you have been responding to other threads which you started.



 
Thanks, the solution worked and helped me a lot. I'll make sure to replay to all answers in the future.

Judy Scofield
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top