View Single Post
  #2  
Old February 17th, 2006, 05:40 AM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Multiple Instances of Form Created By Form Open

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.

--
Wayne Morgan
MS Access MVP


"David S" wrote in message
oups.com...
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.