Hi
Today am going to share about how to prevent the window closing when the data are not saved in the datawindow.
Usually when you did any changes to your data window if you not saved that datawindow and if you clos that datawindow no data will be saved.
So to avoid that and your application users must save the datawindow while before closing the window use the following code to protect the accidental close.
Code follows
Write this code on your windows Close Query Event. Or if you want you can write at base window.
Integer li_count,li_ret
window aw_window
aw_window=this
FOR li_count = 1 TO UpperBound(control[])
IF TypeOf(aw_window.control[li_count])=Datawindow! Then
Datawindow dw
dw=control[li_count]
IF dw.AcceptText() = 1 AND dw.ModifiedCount() > 0 THEN
li_ret=Messagebox('Alert','Changes Not Saved, Do you Want to Save it?',Question!,YesNo!,1)
If li_ret=1 Then Return 1
End if
End if
NEXT
this code is common to all windows you can write this code at your base objects close query event.
Explanation :
aw.control[] this code is used to get the all controls places on the window.
Using the control we are verifying the type using the TypeOf. If the type is datawindow then we are checking is there any modifications happened using the Acceptext() function.
After this we are checking for modified count. Whether the data is changed or not. If so then we are giving the messagebox to ask the user to close or not.
You can also code the datawindow to save automatically when the user click Yes button. Write the update code on the return value loop statement.
dw.update()
thats it.
Regards
Raj
Today am going to share about how to prevent the window closing when the data are not saved in the datawindow.
Usually when you did any changes to your data window if you not saved that datawindow and if you clos that datawindow no data will be saved.
So to avoid that and your application users must save the datawindow while before closing the window use the following code to protect the accidental close.
Code follows
Write this code on your windows Close Query Event. Or if you want you can write at base window.
Integer li_count,li_ret
window aw_window
aw_window=this
FOR li_count = 1 TO UpperBound(control[])
IF TypeOf(aw_window.control[li_count])=Datawindow! Then
Datawindow dw
dw=control[li_count]
IF dw.AcceptText() = 1 AND dw.ModifiedCount() > 0 THEN
li_ret=Messagebox('Alert','Changes Not Saved, Do you Want to Save it?',Question!,YesNo!,1)
If li_ret=1 Then Return 1
End if
End if
NEXT
this code is common to all windows you can write this code at your base objects close query event.
Explanation :
aw.control[] this code is used to get the all controls places on the window.
Using the control we are verifying the type using the TypeOf. If the type is datawindow then we are checking is there any modifications happened using the Acceptext() function.
After this we are checking for modified count. Whether the data is changed or not. If so then we are giving the messagebox to ask the user to close or not.
You can also code the datawindow to save automatically when the user click Yes button. Write the update code on the return value loop statement.
dw.update()
thats it.
Regards
Raj