Close Btn Confirmation

  • Thread starter Thread starter Kay
  • Start date Start date
K

Kay

Hi
I have used a close button on my forms with the following code:

If MsgBox("Are you sure you want to close the form 'Client details'?",
vbYesNo) = vbYes Then
DoCmd.Close
End If

The problem is if more than one form is open, then when I press the
close button to close a form, another form closes instead.

For example if I have client form and employee form open. On the client
form If I press the close button, a confirmation appears and if I press
yes to the confirmation to close the client form, the employee form
closes instead

Can anyone help please, it will be much appreciated
 
Have you got the code behind the OncLick event of the button on the Client
Details form? Have you tried creating the Close button with the button
wizard that normally works fine
Tony
 
Kay said:
Hi
I have used a close button on my forms with the following code:

If MsgBox("Are you sure you want to close the form 'Client details'?",
vbYesNo) = vbYes Then
DoCmd.Close
End If

The problem is if more than one form is open, then when I press the
close button to close a form, another form closes instead.

For example if I have client form and employee form open. On the
client form If I press the close button, a confirmation appears and
if I press yes to the confirmation to close the client form, the
employee form closes instead

Can anyone help please, it will be much appreciated

I don't think that ought to happen unless your close button's code also
opens the other form, or some other event occurs to make the other form
active. However, you can -- and should -- avoid this problem by
specifying the name of the object you want to close. You don't have to
hard-code that, though, if it's the object on which the code is running;
instead, use the object's Name property:

DoCmd.Close acForm, Me.Name

I usually want to also specify that I don't want to save any design
changes to this object:

DoCmd.Close acForm, Me.Name, acSaveNo
 
Hi Guys

Me.name, what does "name" refer to because I want it to close that form
and it does not work when I use me.form.
By the way it does only happen when I open a form from another form, it
closes the form i opened it from.

Any ideas
 
Kay said:
Hi Guys

Me.name, what does "name" refer to because I want it to close that
form and it does not work when I use me.form.
By the way it does only happen when I open a form from another form,
it closes the form i opened it from.

Any ideas

Me.Name is an expression that returns the Name property of the form that
is running the code. You aren't supposed to replace it with anything,
but use exactly the statement as it was posted:

DoCmd.Close acForm, Me.Name

That will close the form in whose module that statement is executed.
 
Back
Top