Docmd.Close Does Not Close Immediately ?

  • Thread starter edisonl via AccessMonster.com
  • Start date
E

edisonl via AccessMonster.com

Hi everyone,

Scenerio:
Private Sub Event Button Cancel_OnClick()
{ Function1
Function2
End sub }

Certain check perform for Function1>
If Not fulfill> Docmd.Close
If Fulfill> Perform something & Go To Function2
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
But my function1 Docmd does not fire immediately and proceed to call Function
2?
Tries to look for one of the controls in the current form (As current form
might been close)
Produce Error> The Object does not accessed or is close, duh !

Can Someone kind enough to explain the logic behind ?

Regards & God Bless, Edison
 
A

Allen Browne

So you have an event procedure in the Click event of a button, that's
supposed to:
a) close the current form (presumably the one that has this button), and
b) do something with another form.

Since this code is in the form's module, it's not surprising that it cannot
release memory until the code has finished running. This means you will need
to pass a reference to the other form if you want function2 to operate on
it.

For example, you might declare function2 like this:
Public Function Function2(frm As Form)
and then call it like this:
Call Function2(Forms![SomeOtherForm])

Then Function2 can operate with frm, e.g.:
If frm.NewRecord Then MsgBox "It's at a new record"
or, if you need it to take focus:
frm.SetFocus
 
E

edisonl via AccessMonster.com

Hi Allen,

Thanks For Replying..


- Basically Form1 Had ConTrols of Cancel_Button.
- Cancel_Button (Calling 2 Sub function, Function1, Function2)
-Function1 Prform Some Checks (If Not Pass, Will Immediate exit Form1, If
PAss Will Call Up To Function2)

-Complex Issue here is that Function 1 & 2 Are Not In Sequence calling, it
depends upon certain
checks ( Eg: Scenerio1, Call Function1 then Function2, Scenerio2, Call
Function2 First then Function1)

- In your suggestion, Do I need to declare both as Public Function ?

Regards & God Bless, Edison

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~
Allen said:
So you have an event procedure in the Click event of a button, that's
supposed to:
a) close the current form (presumably the one that has this button), and
b) do something with another form.

Since this code is in the form's module, it's not surprising that it cannot
release memory until the code has finished running. This means you will need
to pass a reference to the other form if you want function2 to operate on
it.

For example, you might declare function2 like this:
Public Function Function2(frm As Form)
and then call it like this:
Call Function2(Forms![SomeOtherForm])

Then Function2 can operate with frm, e.g.:
If frm.NewRecord Then MsgBox "It's at a new record"
or, if you need it to take focus:
frm.SetFocus
Hi everyone,
[quoted text clipped - 18 lines]
Regards & God Bless, Edison
 
A

Allen Browne

I'm not clear from your question where Function1 and Function2 belong, or
even if they are functions in the VBA sense (of perhaps you must mean some
kind of operation.)

The functions must be public if they are not in the same module as your
event procedure.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.
edisonl via AccessMonster.com said:
Hi Allen,

Thanks For Replying..


- Basically Form1 Had ConTrols of Cancel_Button.
- Cancel_Button (Calling 2 Sub function, Function1, Function2)
-Function1 Prform Some Checks (If Not Pass, Will Immediate exit Form1, If
PAss Will Call Up To Function2)

-Complex Issue here is that Function 1 & 2 Are Not In Sequence calling, it
depends upon certain
checks ( Eg: Scenerio1, Call Function1 then Function2, Scenerio2, Call
Function2 First then Function1)

- In your suggestion, Do I need to declare both as Public Function ?

Regards & God Bless, Edison

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ ~
~ ~ ~ ~ ~ ~ ~ ~ ~
Allen said:
So you have an event procedure in the Click event of a button, that's
supposed to:
a) close the current form (presumably the one that has this button), and
b) do something with another form.

Since this code is in the form's module, it's not surprising that it
cannot
release memory until the code has finished running. This means you will
need
to pass a reference to the other form if you want function2 to operate on
it.

For example, you might declare function2 like this:
Public Function Function2(frm As Form)
and then call it like this:
Call Function2(Forms![SomeOtherForm])

Then Function2 can operate with frm, e.g.:
If frm.NewRecord Then MsgBox "It's at a new record"
or, if you need it to take focus:
frm.SetFocus
Hi everyone,
[quoted text clipped - 18 lines]
Regards & God Bless, Edison
 
J

Jeanette Cunningham

I suggest something like this-->

If Not Function1 = True Then
DoCmd.Close acForm, Me.Name
Else
Perform something & Go To Function2
End If


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

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