Access 2003 - Form buttons must be clicked twice to close form

  • Thread starter Ragnar Midtskogen
  • Start date
R

Ragnar Midtskogen

Hello,

I got the job of fixing a problem in an Access 2003 application.
The problem is a small form used to add items to a combobox list by updating
the underlying table.
The form has two command buttons, OK and Cancel.

The OK button calls a sub to add the contents of a couple of text boxes to
the table, then it tries to close the form, named frmEditBox with this code:
DoCmd.Close acForm, Form_FrmEditBox.Name
To close the form always takes two clicks.

The form also has a Cancel button with this code
DoCmd.Close acForm, Form_FrmEditBox.Name
Same thing, need to click twice to close the form.

However, if I click the OK button first, then the Cancel button, the form
closes.

My first idea was that this must have something to do with a focus event,
but I can't find any code that gets fired other than the button click
events.

Any help on this would be appreciated.

Ragnar
 
B

Barry Gilbert

I'm not sure if this is related to your problem, but you could shorten
this statement to

DoCmd.Close

It will infer that you want to close the containing form.

Barry
 
G

Guest

Post back with the full code in the OK button click event and the full code
in the Cancel button click event, please. It is difficult to debug code that
we can't see.
 
R

Ragnar Midtskogen

Thank you Klatuu,

That is the full code for the Cancel button.
The code for the OK button is actually in function that would not work
unless you have all the other objects referenced, but if I comment out the
function call and use the same statement as for the Cancel button, I still
have to click twice.
I have considered the possibility that the form is corrupted, but I have not
tried recreating it yet.

Forgot to mention, the form is unbased.

Also for got to mention that I have worked in Access since 1996, starting
with Access 2 and working my way through every version up to 2000, but this
is my first real experience with 2003.

Ragnar
 
R

Ragnar Midtskogen

Thanks Barry,

I have not tried, but I have always had best luck with fully qualified
statements, besides, the statement for the OK button is actually in a
function called from the OK button's event proc. so the implied reference
would not work.

Forgot to mention that I have worked in Access since 1996, starting with
Access 2 and working my way through every version up to 2000, but this
is my first real experience with 2003. I have never seen this before, so I
was wondering if this is something unique to 2003.

Ragnar
 
D

david epsom dot com dot au

Do you have a 'form error' or 'not in list' event?

If it is not a simple focus problem, I would say that
an event is being cancelled.

(david)
 
R

Ragnar Midtskogen

Thank you David,

I have looked at that too, but I have not found any. Aside from the two
button events there is one for an optiongroup.

If the client wants to do anything more I am going to create a new form, to
see if this is a corruption problem.

Ragnar
 
A

Albert D.Kallal

Forgot to mention that I have worked in Access since 1996, starting with
Access 2 and working my way through every version up to 2000, but this
is my first real experience with 2003. I have never seen this before, so I
was wondering if this is something unique to 2003.



Note the following



DoCmd.Close acForm, Form_FrmEditBox.Name



OUCH!!!!! Game show buzzer. Who EVER suggested that you reference ANY forms
property by using the forms base object?



YOU NEVER EVER EVER want to use



form_EditBox



The above is the WRONG way to reference a form. You MUST USE



forms!FrmEditBox.name

or

forms("FrmEditBox").name

or perhaps

forms(3).name

(assuming you know which index number in the forms collection your form is).



Using the forms base object name such as



fomr_FrmEditBox.name will case many problems



#1 problem. If the form is NOT opened, then referencing ANY property or
method of the forms object will case the form to LOAD!!!!!! This means that
the ON-LOAD AND ON-OPEN events...and on ACTIVATE EVENT will FIRE IF THE FORM
IS NOT OPEN!!!!!



Assuming FrmEditbox is closed, then ironically, the following command would
actually LOAD THE FORM!!!!...the form events would fire...and the form will
close!



DoCmd.Close acForm, Form_FrmEditBox.Name



#2 problem. If the form is loaded as sub-form, then the above will actually
reference the first occurrence of that sub-form loaded. (this means you will
accident be referencing the form as a sub-form...not the base form).
Further, if there is more then one instance of the form loaded, then the
reference will be the first form (really difficult to know what instance of
the form you are using - and if a sub-form is in use..then you very well may
be referring to the wrong form).



#3 problem

If the form does NOT have any code, then using this reference style will
FAIL!!! (no base object is created if the form has no code).





#4 problem

There is so many more problems to list that I will stop!!!



To say that the above syntax is bad is a understatement on my part
(especially given the amount of time you worked with ms-access).



For me to stress any harder as to how bad this incorrect referencing is
would make me a un-kind person.....I really don't want to be a un-kind
person....



So, in kind words, you REALLY do not want to use the base class object as
your means to reference a form . The worst problem of course is that if the
form is not loaded, then the form WILL be loaded.and the events fire!!



For example, try the following (frmEditBox closed). Type the following
commands in the debug.window.



debug.print forms.Count

debug.print Form_FrmEditBox.Name

debug.print forms.Count



You will note that the form is now loaded!!!



Now type

FrmEditBox.Visible



Further.



I can't say the above lecture on how to use forms in ms-access is the root
of your problem but, a good starting point here would be to correct your
code.



Do note that in versions after access 97, you can NOT reference the base
object of a class module. (but then, you must ask how can access 97 code be
converted to, and run in a2000 and later? Answer: there is hidden compiler
directive that you can change in a2000 and later that WILL allow you to do
this - but obviously this is a STRONGLY discouraged practice in vb, or
ms-access) If you care for details on how to accomplish this in a2000 or
later.just ask..and I will show you how this works..
 
G

Guest

I do not believe this is a 2003 issue. I have been using 2003 for over a
year now, and have not seen this problem. Is is possible the form is Dirty
and some other event is canceling?

I would put a break on the DoCmd.Close line, check to see if the form is
dirty, and step through it. I might also try entering Me.Dirty = False from
the immediate window and see what happens.
 
M

Michael Fuchs

Ragnar,

did you solve your problem?

I'm having the same problem here, only that I have to click the close
button three times before the form closes.

Mike
 
M

Michael Fuchs

Ragnar,

did you solve your problem?

I'm having the same problem here, only that I have to click the close
button three times before the form closes.

Mike


Ragnar said:
Thank you David,

I have looked at that too, but I have not found any. Aside from the
two button events there is one for an optiongroup.
If the client wants to do anything more I am going to create a new
form, to see if this is a corruption problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top