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

Datagrid Validation

Status
Not open for further replies.

evoluder

MIS
Dec 4, 2001
21
0
0
US
Hello everyone, I have a datagrid question I hope you can help me with. Let me explain:

I have a datagrid that is bound to a client side ADO recordset. The user is required to press a toolbar button before she is able to edit cells in the datagrid. After pressing the toolbar button, all cells in the datagrid may be modified. I use the DataGrid1_BeforeUpdate event to validate the new data. This works great when the user moves around the datagrid. However, if the user inputs invalid data in a cell, and then presses the toolbar button to exit “edit mode” the application generates an error: “Multiple-step operation generated errors. Check each status value.” The toolbar_click event doesn’t have a chance to fire before the error is generated, nor does datagrid1_validate or beforeupdate. The invalid data can be any value that exceeds the max value for the datatype in the database (Access), e.g. too large a number for an Integer field, or too many characters for a length-limited text field, etc.

For some reason the DataGrid1_BeforeUpdate event doesn’t fire when clicking on the toolbar but the invalid data is put somewhere that causes the error to be generated.

Any idea what I am doing wrong?

TIA
 
1. Update to MDAC 2.6
2. Do not use the DafaultValue property
3. Use a form level recordset object variable declared using WithEvents.
Then add the events WillChangeField and WillChangeRecord.

Check the adStatus for adStatusErrorsOccured and the field values for a illegal input, and either change the value or cancel it.

Set the status to adStatusUnwantedEvent to cancel the messages.
[/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!
 
CCLINT,

Thanks for the note, I'll give it a shot. I haven't played around with the recordset events much so I'll have to do some research.

Cheers.
 
CCLINT,

I tried your suggestion, but what I am finding is that the Recordset events are not being called before the error occurs. The "Multiple-Step" error I wrote about above is being generated by the Datagrid control before the Recordset sees anything. On a cell value change that doesn't generate an error the recordset events fire off nicely. Any other ideas why this would be happening?

Thanks again for your time.
 
Hmm.
1. Which version of ADO are you using/which version of MDAC is install?

2. Have you updated to VB6 SP5?

3. Does the BeforeColUpdate event fire prior to the error? [/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!
 
1. ADO: 2.7, MDAC: 2.7
2. SP5, Yup.
3. Check out the following KB article on MSFT: Q288346


It specifically mentions the BeforeUpdate event but it is precisely the behavior I am seeing so I assume that the beforecolupdate event is related in the sequence just right so that my validation breaks. Yesterday I worked with the datagrid_change event and I can get some validation to work but it seems to be a bit of a kludge. If I want to stop an 8 character text field at 8 chars, the database field has to be set at 9 chars because the change event doesn't fire until after the error is thrown up!

This combined with a few other issues with the datagrid control has me thinking about buying a more full featured one or trying the vb.net stuff. Do you know if the controls in .Net are much different? Have you talked to anyone who has tried migrating a vb6 app to .NET?

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top