Multiple Instances of Form Created By Form Open

  • Thread starter Thread starter David S
  • Start date Start date
D

David S

I'm using Access 2002 on Windows 2000. I have a search form where the
user selects a row in the subform data sheet and then clicks an open
button to bring up another form with the data related to the row they
selected. The open button runs some simple code that does a form open
based on the primary key field in the subform. In testing, our QA
inadvertently clicked multiple times on the open button and ended
creating 10 plus instances of the form (I didn't think this was
possible in Access) and if you try to click on one of the instances
Access crashes.

I tried disabling the open button as the first action in the on_click
event and I also tried checking to see if the form was already open
before executing the Docmd.OpenForm, but that didn't help. This
strange behavior only happens about every 20th time the QA tries
multiple clicks. Is this some strange Access bug? Any ideas or
suggestions would be greatly appreciated.

Thanks, David.
 
To disable the button, you must first move the focus to another control with
a SetFocus statement. Checking to see if the form is open before running the
code should work unless the user is clicking so quickly that the form isn't
detected as being open yet. If that's the case, after the OpenForm command,
try issuing a SetFocus command to the form you just opened followed by a
DoEvents statement to allow the system to catch up. Another option would be
to set a "flag" variable when you open the form and check the value of the
flag before you allow the form to open. This value will take effect
immediately and so should be available the next time you run through the
code. You will also need to clear the value of this variable when you close
the form. This could be done in the pop-up's Close event. Since the variable
will be accessed from more than one form, it should be a Global variable and
declared (Dim'ed) in a standard module.
 
David S said:
I'm using Access 2002 on Windows 2000. I have a search form where the
user selects a row in the subform data sheet and then clicks an open
button to bring up another form with the data related to the row they
selected. The open button runs some simple code that does a form open
based on the primary key field in the subform. In testing, our QA
inadvertently clicked multiple times on the open button and ended
creating 10 plus instances of the form (I didn't think this was
possible in Access) and if you try to click on one of the instances
Access crashes.

That shouldn't be possible using "simple code", though it is possible
using code that I would consider "advanced". What is the code behind
the button?
 
The code uses ADO to load some local tables and then does a
docmd.openform and a docmd.close to close the search form. The form
being opened resets its recordset based on the ID that was selected on
the search form. The one unique thing about the form is that it uses
the spreadsheet control.

It seems that this issue is specific to Office XP Service Pack 2. We
can't recreate it on my machine that's running SP1 and when we upgraded
the QA's machine to SP3 she could no longer seem to create the issue
(she's going to do more testing tomorrow).

I've tried some of Wayne's suggestions and the error still occurred. I
also tried putting a log function in the routines being executed and my
code only runs once. I also was able to get back to Access when the
extra forms were displayed and Access only thought there was one form
open. If you try and click on one of the extra forms Access crashes.
When Access displayed its closing message we said "send report" and
followed the prompts -- the messages seemed to indicate that this was a
known problem and that we should install SP3.

-- David.
 
David,

Thanks for the follow up. Yes, if SP3 fixes it, then it sounds as if you've
found your solution. As Dirk had mentioned, "it shouldn't do that" without
some special coding on your part.
 
Back
Top