Home » Microsoft TechnologiesRSS

Form Closing Event

I am very new to VB.  I am using the online msdn tutorial http://msdn.microsoft.com/en-us/library/ms172599(v=VS.90).aspx to create and use a SQL database.  Creating and linking the database went fine.  Running the app in VB2010 Express worked fine, until the step that has me adding an event for form.closing.  I used cut and paste from the online tutorial, and it is supposed to automatically save changes on exiting, but clicking the X in the application window does not close the program.  No error is dispayed.  I have to use the stop debugging button in VB to get the app to close, and no new data is saved.  Has anyone else used the above tutorial with a problem, or success?  I am running win7 home, and VB2010 express.  I wonder if the file is inaccessable to the form.closing event.  If I delete the for.closing event, I can manually save new data and it saves, so I'm confused.

Thanks in advance for the replies

 

6 Answers Found

 

Answer 1

I can't speak specifically to your issue but have you tried putting a breakpoint in and watching to see just what it does during the form's closing?
 

Answer 2

Frank, thanks for the suggestion.  I'll have to read up on how to do that, as I am only two days into to VB and learning on the fly.
 

Answer 3

Frank, thanks for the suggestion.  I'll have to read up on how to do that, as I am only two days into to VB and learning on the fly.


Call me impressed then. After just two days I was still trying to figure out what "VB" stood for. :-o

See if this will help:

http://www.fls-tech.com/VBNet_Forum/UsingBreakpoints/

It's done in Flash and is about a minute and half long.

 

Answer 4

While looking into breakpoints, I found a debug tool for "Immediate", and these are the results.

Firstly, this is the code, as instructed in the tutorial;

  Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Me.AddressesBindingSource.EndEdit()
    Me.AddressesTableAdapter.Update(Me.FirstDatabaseDataSet.Addresses)
  End Sub

Next, the error  message from "Immediate" generates every time I click the X to close  the program;

A first chance exception of type 'System.NotImplementedException' occurred in Addresses.exe

Still looking into using the Breakpoints.

 

 

 

 

Answer 5

Could it have actually been that when I selected the Form.Closing event, that it placed it in the wrong spot.  I just moved it from after the 'load form' sub to above the 'load form' event, and it seems to be working now.  I'm going to run through the tutorial  again, but it seems like vb2010  placed it in after the form  load on several tries, and I am fairly certian that is all I changed.

 

*correction* I changed the code.  I used the code from the save  data button  instead of what the tutorial showed.

Non- working code =   Me.AddressesBindingSource.EndEdit()
        Me.AddressesTableAdapter.Update(Me.FirstDatabaseDataSet.Addresses)

 

Working code = Me.AddressesBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.FirstDatabaseDataSet1)

 

Answer 6

Could it have actually been that when I selected the Form.Closing event, that it placed it in the wrong spot.  I just moved it from after the 'load form' sub to above the 'load form' event, and it seems to be working now.  I'm going to run through the tutorial  again, but it seems like vb2010  placed it in after the form  load on several tries, and I am fairly certian that is all I changed.

 

*correction* I changed the code.  I used the code from the save  data button  instead of what the tutorial showed.

Non- working code =   Me.AddressesBindingSource.EndEdit()
        Me.AddressesTableAdapter.Update(Me.FirstDatabaseDataSet.Addresses)

 

Working code = Me.AddressesBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.FirstDatabaseDataSet1)


I hope you've found it. It doesn't matter where (in a particular order that is) the event  handler is. So long as it's in the class for that form, it'll fire.
 
 
Search for  Form Closing Event
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter