Code Execution Sequence when Instancing Form

  • Thread starter Thread starter Hector Cabrera via AccessMonster.com
  • Start date Start date
H

Hector Cabrera via AccessMonster.com

I want to create a form based on say "Form1" through Access VBA code.
I want to colled data on the instance of Form1 (myFormInst).
However, the rest of the code (see msgbox)keeps runing.
I want the focus to go to myFormInst until data is collected.
Then I want to return to the next line (In this case the msgbox).
When I run this code myFormInst blips for a sec,
then goes away and the msgbox shows up???

Dim myFormInst As Form_Form1
Set myFormInst= New Form_Form1

myFormInst.Visible = True
myFormInst.SetFocus
MsgBox "I am doing this now"
 
You need to indicate that whatever is to be done using Form1 is complete,
and poll for that indicator. For example, you might create a property in
Form1:

Property Get Completed() As Booleand
Completed = mblnCompleted
End Property

Within Form1, set the value of mblnCompleted to true after it has finished
collecting entries.

Then, poll for the completed indicator:

myFormInst.Visible = True
myFormInst.SetFocus

Do Until myFormInst.Completed = True
DoEvents
Loop

MsgBox "I am done now"
 
Thanks !
Because I have events in the form I automatically had thought that I had to
declare the form "withEvents" and could only run it using the "DIM" and
"SET" commands. It never occurred to me to try the DoCmd to see if the
events would work.
 
Thanks !

The polling solution presented by Paul may be the only one that could work
in my case because I have events on the form I want to use. The only way I
know to declare Events is dimensioning an instance of the form class like
this:

Alternative # 1
Private withEvents myFormInst as myFormClassName(byVal dVal as whatever)

Once I do this I can not use the DoCmd to open myFormInst in acDialog mode,
or can I?
 
Back
Top