Dear all,

i have a project created in VB. and the database in MS Access. I created a menu driven programme. in file menu i inserted command named exit and in the click event i wrote End. it is working but when i click on the close button of the MDi from the project didn't close properly. the window is hide but the programme is running in the background. each time i have to clisk teh combination keys Ctrl Alt Del and go to task manager and stop the programme. is ther any solution for it. if so pls tell me

thanks

vijesh

let me know something!
you have a MDIform.. the exit file with the command end is on the MDI form? or on another one?

or you can try to see.. if you have a bas module or in project properties.. wich form / modul is the first running when you start the application! becuase you may have: form1 the first loaded form and then a MIDI form... and there is the posibility when you will close the MIDI the application to be running.

second.. wgat i understand formn you is.. that you have a menu/button named exit with command end... but you want to close the mdi from title bar close button. if so.. add and end at that property too.

if not send me an example

Create a Module (Code Module) and add this:

Sub Die()
for each XFrm in Forms
     unload XFrm
next XFrm

end
end sub

Then, in your project on the "exit" menu, AND in the main windows form_unload, just do this: Die This method, actually is 100,000 times better than using end... it's much more graceful, and it gives all the forms an opportunity to clean up after themselves. Then, any and every place you need to end the main program, just call the Die sub, and you are good to go.

hmmm . . . thats a neat technique, though for the record, if you have Option Explicit in your module you will need to Dim Xfrm as Form in that procedure.

That's absolutely right. It's not often that people use option explicit, since VB allows you to be Sloppy and Creative... and beyond that, you should declare all your variables anyway, using option explicit or not....so you are absolutely right:

Public Sub Die()
Dim XFrm as Form
for each XFrm in Forms
     unload XFrm
next XFrm

end
end sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.