Stop VBA execution when sub form gets focus

A

Andy Stevenson

Hi,

I'm a little stumped... I know I can open a form in dialogue mode & VBA will
patiently sit & wait for the form to close before carrying on. But I can't
get this to happen with a subform.

What I'm trying to do is this:

The user clicks a command button on the main form & the onclick event loops
through a list of invoices, picking up items from a table as it goes. When
it gets to an item on the invoice that it can't find in the table, a sub
form is made visible & given the focus, I need the VBA loop to pause while
the user fills in the form then clicks a command button on the subform that
hides it & allows the loop to continue.

I had hoped that setting the subform to Modal & Popup would do the trick,
but it seems not. The loop refuses to pause.

Any ideas greatly appreciated.

Thanks.

Andy.
 
A

Albert D.Kallal

A few things:

I can put a text box control on a form. Lets put 3 on a form, lets call the
controls

zoo1
zoo2
zoo3

After I place those 3 controls on the form, then can set the datasource of
ALL 3 controls to the SAME field. So, we can set zoo1 to be attached to a
field called

LastName

Note that we can do this for all 3 text box controls. I point this out,
since the name of the control does NOT have to be the same as the underlying
data field. This also means that you can place 3 text boxes on a form, and
they all point to the same field.

It is important to note that a sub-form is not a sub-form, but a sub-form
CONTROL. This is a simple control that you place on a form. AFTER you place
this control on the form, you THEN set what sub-form this control will
display. This means that you can have 3 sub-form controls called apple1,
apple2, apple3, and they ALL POINT TO THE SAME sub-form. (each form that the
control points to will create a instance of that form).

So, this sub-form control again just like the text box control does NOT have
to have the same name as the sub-form. This means that a sub-form is simply
a control that you place on the form (it even has enter, and exit events).
So, you can simply set the focus to this contorl...and it certainly will NOT
halt code. Hence, your idea that changing forms property to model etc. will
not work, since the focus is actually being set to a sub-form control. With
this concept in light, then you can see that your idea will not work.

Further, when you set, or open a form as model, it NEVER did halt code. And,
the same goes for a popup setting....as again, this setting NEVER did halt
calling code. So, not only is a sub-form not really a sub-form, but a
control on a form, your idea that setting a form to model NEVER did halt
code anyway.

You can open a form in dialog mode...but that is done via the docmd.openform
command, and certainly does NOT apply to controls like text boxes, or in our
case the sub-form control on that form.

I would either change your design so as to not require the need to halt the
code. The main code could simply make the sub-form visible, and upon
clicking some button, then the sub-form could then run a parent form code
(this is how event driven programming works anyway. So, get away from a
"procedure" approach..and simply have the sub-form *CALL* the code in the
parent....not the other way around.

The other solution would be to NOT use a sub-form, and use a dialog form..as
that DOES halt calling code. So, I think this is a case were you don't want
to use a sub-form control.

As for the confusing between dialog forms,a nd model forms (which are VERY
VERY different), you can read about how to use a dialog form here:

http://www.members.shaw.ca/AlbertKallal/Dialog/Index.html

The above article of mine does show you how to "open" a form..and have it
return values (and, if you use my 2nd suggestion, then you WILL find this
article of use to you).
 
A

Andy Stevenson

[snip]
It is important to note that a sub-form is not a sub-form, but a sub-form
CONTROL. This is a simple control that you place on a form. AFTER you
place this control on the form, you THEN set what sub-form this control
will display. This means that you can have 3 sub-form controls called
apple1, apple2, apple3, and they ALL POINT TO THE SAME sub-form. (each
form that the control points to will create a instance of that form).

Ah, ok. when is a form not a form. When it's a sub form. Got it.

[snip]
I would either change your design so as to not require the need to halt
the code. The main code could simply make the sub-form visible, and upon
clicking some button, then the sub-form could then run a parent form code
(this is how event driven programming works anyway. So, get away from a
"procedure" approach..and simply have the sub-form *CALL* the code in the
parent....not the other way around.

The other solution would be to NOT use a sub-form, and use a dialog
form..as that DOES halt calling code. So, I think this is a case were you
don't want to use a sub-form control.

Rethink now underway :)

[snip]
http://www.members.shaw.ca/AlbertKallal/Dialog/Index.html

The above article of mine does show you how to "open" a form..and have it
return values (and, if you use my 2nd suggestion, then you WILL find this
article of use to you).

Indeed, very useful. Thank you Albert.
 

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