Albert,
To illustrate how things work in Access, follow this procedure:
1. Create two identical forms, Form-A and Form-B.
2. Put a command button and a textbox (named Text1) on each form.
3. Add the following code to the Click event of the button on each form.
Dim ctr As Long
Debug.Print "Form-A start"
For ctr = 1 To 100000
Me.Text1 = ctr
DoEvents
Next ctr
Debug.Print "Form-B finish"
4. Change the Debug.Print statements on Form-B as follows:
Debug.Print "Form-B start"
Debug.Print "Form-B finish"
5. Save the forms, then open both of them.
6. As quickly as you can, click the button on both forms.
You'll notice that Form-A's code starts to execute until you click the
button on Form-B. This is because Form-B's Click event generates an
Interrupt, which passes immediate control to Form-B. Form-B's code will
continue to execute until it either naturally completes, or is interrupted
by a system event (like another Click event) elsewhere, after which it will
return control to Form-A.
If you check the Immediate window, you'll see the following:
Form-A start
Form-B start
Form-B end
Form-A end
So you see that, ignoring the interrupts themselves, there is no threading
going on here. Code is executing procedurally.
Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
"Albert" <(E-Mail Removed)> wrote in message
news:e9fUird%(E-Mail Removed)...
> Thanks for your reply.
>
> But my case, 1st form does not call 2nd form. Both form can be opened
> directly by user. Is this multi-thread ?
>
> Thanks,
> Albert
>
> "Graham R Seach" <(E-Mail Removed)> wrote in message
> news:Ogo9xEd#(E-Mail Removed)...
> > Albert,
> >
> > You can't stop it from happening. The behaviour you experience is by
> design.
> >
> > Access does not spawn a new thread for every module, so all code (with
the
> > exception of asynchronous database operations) will run procedurally
(one
> > after the other). If your main form calls a procedure in a subform or
> other
> > module, thereby passing control to it, that code will execute until it
has
> > finished, after which it passes control back to the procedure that
called
> > it.
> >
> > Regards,
> > Graham R Seach
> > Microsoft Access MVP
> > Sydney, Australia
> >
> > "Albert" <(E-Mail Removed)> wrote in message
> > news:eZJ%23UBd%(E-Mail Removed)...
> > > Hello,
> > >
> > > I have a form do some operations in looping. Due to it takes a long
> time,
> > I
> > > insert DoEvents() in this loop. I have another form do some looping
and
> it
> > > includes DoEvents() also. Both form possible to run at the same time.
> > > Problem I found is whenever second form (any form) is run ,if first
form
> > is
> > > in looping, second form DoEvents() will pause first form looping. When
> > > second form quit looping, First form continue looping.
> > >
> > > How to solve this ?
> > >
> > > TIA,
> > > Albert
> > >
> > >
> >
> >
>
>
|