mike55 Posted December 4, 2008 Posted December 4, 2008 (edited) Hi all I have a dateset whose contents can be changed by the user. Usually the user would click the save button when they are finished making the changes. However, if they forget to click on the save button, I want to simply offer them the opportunity to do so when the FormClosing event is fired. Here is my code so far: Private Sub frmGeneralQueries_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Select Case mintReport Case frmMain.mcTotalByOrganisation If Not dsPRTRDisplay.Tables("TotalByOrganisation").GetChanges.Rows.Count = 0 Then If MessageBox.Show("Your changes have not been saved. Do you want to Save them?", "Save Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then AllowSaveChanges() End If End If End Select End Sub The above code works in the event that there was a change that the user had not already save, however, I am getting problems if no changes exist. I know that I could use dataset.haschanges, however, there is no guarantee that the dataset in question would only have one table in it. Error message is: NullReferenceException - Object Reference not set to an instance of an object. Any suggestions? Mike55. Edited December 4, 2008 by mike55 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted December 8, 2008 Administrators Posted December 8, 2008 Try If Not dsPRTRDisplay.Tables("TotalByOrganisation").GetChanges Is Nothing instead and see if that works. IIRC GetChanges will return nothing if there are no modified records. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.