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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture size of data in Datagrid

Status
Not open for further replies.

Bloobird

Programmer
Oct 23, 2001
49
GB
Hi - I have a quick maintenance form using an Adodc and Datagrid. Basically, if I update the text in a grid, if it exceeds the size of the field in ther database, I get 'Multiple -step operation generated errors. Check each status value'. Is there a way I can either limit the datagrid to allow only a set number of characters to be entered, or capture the text after editing, so I can remove trailing spaces which make it exceed the database field size, before error occurs ?

Thanks
 
You can use the BeforeColUpdate event to catch the value before it gets written to the database and can cancel the update
 
Hi - I've tried the following code previously

Private Sub DataGrid1_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
With DataGrid1
If Len(.Columns(.Col).Value) > 50 Then
.Columns(.Col).Value = Left(.Columns(.Col).Value, 50)
End If
End With
End Sub

But the error message still occurs...
 

Try just adding:

Cancel = True

before setting the column to the changed (corrected) value.

You could also add the following code in the KeyPress event:

Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii < 32 Then Exit Sub
If Len(DataGrid1.Columns(DataGrid1.col).Value) > 50 Then KeyAscii = 0
End Sub

[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks guys, that seems to have done the trick ...!
 

You are welcome. [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top