And since Bob is not logged in I'll point out that it appears that it is his method which is flawed - Sometimes it will close all of the forms and sometimes it will not not. I think it has to do with the way the forms are enumerated -
Would someone be so kind as to run both code samples and confirm which code works? My code works well on my machine. It may be just a difference in our MS Access versions - His code may work well in what he uses and vice versa. I'm using 2003 - ?
Hum... I created three forms and put my code behind a button on one of them, one button with his code on another form and the third form was just blank. Then I opened all three and hit my button and it always closed them all. Then I opened them all and tried his code and some times all of them closed but most of the time it left one or more forms open. I'll point out that I changed the order in which I opened them and could not find a pattern as to which form(s) seemed to stay open when I run his code... ???
Okay, I just did another test and opened 4 forms and I admit that mine did leave one open when I did one of the tests. I apologize. I must have just been lucky when using it.
Mine closed all 9 forms with both codes. I just tried it again.
I don't know if it makes any difference.....but the 9 forms opened are 9 that stay open. However, in the start up process a couple of other forms are opened (used for SetValues) and closed.
As a side note I hope you blokes don't mind if I stick with my macro that closes the 9 forms
I just tried Bobs on a frontend version of the DB and put the code on a textbox, button and label. In each case it only closed the form that had the button, label and textbox.
Then put your code behind the label, textbox and button and all forms closed.