Close form failure

  • Thread starter Thread starter Howard Jacobs
  • Start date Start date
H

Howard Jacobs

The following code on a button click event is causing me problems:

intX = MsgBox("Before close", vbOKOnly)
DoCmd.Close acForm, Me.Name
intX = MsgBox("After close", vbOKOnly)

BOTH message boxes display sequentially. Why doesn't processing stop
at the "close form"?

What actually happens is that processing comtinues until another close
is encountered. At this point, it seems to me, the first close
closes the form and the second one closes the database, leaving me
with an empty Access desktop.

There is the standard On Error staement at the start of the
subroutine.
 
Howard,

The display of both message boxes is expected. A procedure running from
a form's module does not stop just because the form is closed.

Is there a problem? It is not clear from your post what the purpose of
intX is, nor can I understand your reference to the "second close".
Maybe you could explain what you are trying to achieve.
 
what is the purpose of intX
They are just so that I could be sure processing was going "thru" the
close - which I was not expecting to happen.
Maybe you could explain what you are trying to achieve.
The code is in a procedure called by the procedure in the on_click
event of a command button.
At this point, I wish to close the form & return to the calling form
without processing any more code.
A procedure running from a form's module does not stop just because the form is closed.
I did not realize this. How then do I stop code running & get out?
If I add an exit sub, it will get me out of this procedure but won't I
just end up back in the calling procedure?

Thank you, Howard
 
Howard,

Do I understand you correctly?... You have two forms, let's call them
FirstForm and SecondForm. On FirstForm there is a Command Button whose
Click event has code of this structure:
Do Some Stuff
Call ProcedureOnSecondForm
Do Some Other Stuff

The ProcedureOnSecondForm is of this structure:
Do Something
If SomeCondition Is True Then
Close SecondForm
Exit Sub
Do not do the 'Do Some Other Stuff' on FirstForm
End If

How am I doing? Is that the basic idea? If so, I would imagine the
testing of the SomeCondition could be done within the FirstForm
procedure. And if so, this would probably be easier to manage?

Otherwise, you will probably need to give us some more details of your
code and the desired outcome.
 
Steve:

Only one form:

Command button's on_click event:
Procedure1:
Do Some Stuff
Call Procedure2
Do Some Other Stuff
exit sub

Procedure2:
Do Something
If (BadThing)Then
Close Form Now & Do not do the 'Do Some Other Stuff' in Procedure1
exit sub
End If
Do something else
exit sub

Howard
 
Howard,

Here is one possible approach:

-----------------
' Module level variable
Dim GoAhead As Boolean

Command button's on_click event:
Procedure1:
GoAhead = True
Do Some Stuff
Call Procedure2
If GoAhead Then
Do Some Other Stuff
End If
End Sub

Procedure2:
Do Something
If (BadThing)Then
GoAhead = False
Close Form
Else
Do something else
End If
End Sub
 
Hi,
When I have a situation like this, I always make the 2nd procedure a function that returns true on success and
false on failure.

So in the 1st procedure you would have:

Procedure1:
Do Some Stuff
If Not Procedure2() Then
'close form here
End If
Do Some Other Stuff
 
Steve:

I was under a major misunderstanding of what "Close form" did.

Thanks to your help I know see where I was wrong.

I will have to go back to some of my older work & recheck it.

Thank you for your assistance.

Howard
 
Back
Top