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!

How do I cancel an update to datagrid?

Status
Not open for further replies.

gadgetguy1111

IS-IT--Management
Mar 19, 2002
20
0
0
SG
hello,

I'm using a datagrid to allow my user to make changes to the data in a recordset.

currently, i am using the datagrid_AfterColEdit event to allow me validate the information changed.

the problem is i don't know how to cancel the update should the information changed be tested invalid.

any idea how to cancel an update to a datagrid?
am i using the correct event?

thanks.

 
hi,

use this event for Cancelling an update ->

Private Sub DBGrid1_BeforeUpdate(Cancel As Integer)
if data = wrong then
Cancel = True
end if
End Sub

but of u also need to track the column number and stuff (which am sure u need to) then u will have to use both the events, where the colIndex will be trapped in the _AfterColEdit event and the validation and cancelation if any will be done in the _BeforeUpdate event.

Would suggest that put msgboxes in all the events to track which event gets fired first and then onward... which will help u to track the values during a single update.

Hope this helps else donot hesitate to write back....

[cheers]
Niraj [noevil]
 
You may want to track when _AfterColEdit() is activated. If you are moving off the current record to a different one, the underlying database gets updated automatically and you cannot undo it without modifying the record yourself.

Jason
 
hello Niraj,

your suggestion didn't really worked as the the event is triggered before the change is completed. eg i had originally entered 200 into the grid and would like to change it to 1000. Correct me if i am wrong here, i don't think i can key in the 1000. the event is triggered when i keyed 1. hence, the figure in the grid after the event is still 200.

Are there other simple ways where I can cancel the update after the user completes editing the in the grid?


thanks for your help.

:)
--
Boon Kee
 
hello jason,

yes. u are right. the _AfterColEdit() does allow me to do the validation. the problem is if i find an error in the value, how do i cancel the update to the recordset?

thanks.

:)

--
Boon Kee
 
ok.... u guys r right incase each and every column needs to be validated then

use the below events in sync ->

Private Sub DBGrid1_AfterColEdit(ByVal ColIndex As Integer)
MsgBox "DBGrid1_AfterColEdit -> Third"
End Sub

Private Sub DBGrid1_AfterColUpdate(ByVal ColIndex As Integer)
MsgBox "DBGrid1_AfterColUpdate - > Second"
End Sub

Private Sub DBGrid1_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
MsgBox "DBGrid1_BeforeColUpdate - > First"
End Sub


Try this... else post ur code with comments of what is to be validated.... we'll check

[cheers]
Niraj [noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top