Form blocking without being dialog

  • Thread starter Thread starter Eric Ellsworth
  • Start date Start date
E

Eric Ellsworth

Hi all,
I have a form which needs to block the execution of the code, but the
form cannot be pop and modal as dialogs are. I have head that using a loop
with DoEvents is slow and can sometimes crash a system. What do folks
recommend for this problem.

BTW, I have tried loading the form as a dialog and then attempting to set
the Popup and Modal properties, but one gave an error that it could not be
set in the present context, and changing the other seemed to make for an
unexpected code execution path that caused several errors.

Many thanks for any help,

Eric
 
Eric Ellsworth said:
Hi all,
I have a form which needs to block the execution of the code, but the
form cannot be pop and modal as dialogs are.

Why not? You don't make any case as to why the form can not be (or should
not be) model?

If you pop up a form that ask the user for some info, and they accidentally
bump, or click on another form that comes to the front, then you are toast.
The user will think the application has stopped responding, and do a
ctrl-alt del. Likely this will just encourage your users to blow out and
corrupt the ms-access file.

If you are opening a form to halt the calling code, then I can't begin to
come up with some reason, or idea as to why you would not want that form to
be both model,and also be Dialog?

You can certainly consider the idea of opening a form in model (and the
calling code will NOT halt).

Perhaps you are trying to pop open a form, and have the code wait while the
user enters data, and then upon clicking ok, the calling code continues? If
that is the case, then you can use a acDialog form to accomplish this (and,
just to be clear, there is a big difference between a model form, and a
acDialog form in ms-access).
I have head that using a loop
with DoEvents is slow and can sometimes crash a system. What do folks
recommend for this problem.

I kind of argeee. You can start developing your own event loops, but why? I
would try other approahces first. You rpobably can get away using a
"isloaded" function to test while the form is open...but you have made zero
case as to why you need to do this. You also have made no case as to why you
can't use a acDialog form?

You can also use the event driven model, and when the model form closees,
you an have it pass back values, or run code in the calling form. This is
probably the best solution.

However, you can use acDialog forms as follows:

Of course, if code opens a form, it does NOT wait, the calling code
continues to run. Thus, what we need is the call code (the docmd.Openform)
to halt, and wait while the user selects some value from the prompt form.
When done, then your calling code can examine the form' values.

Ok, here is how you do it. You open the form in acDialog mode. This will
halt the calling code, and wait. The user then enters some data into fields,
and the hits the ok button. The trick here is that the ok button DOES NOT
close the form, but sets the forms visible property to false. The will cause
the form to drop out of acDialog mode, and then the calling code will
continue!. If the user does in fact hit cancel, or closes the form, you
consider that as a CANCEL!! (ie: the cancel, or even the "X" in the upper
right corner is thus considered a close/cancel).

Hence, the code looks as

' lets open a prompt form
strF = "frmGetComboName"
docmd.OpenForm strF,acNormal,,,,acDialog

' the above code opens our form "frmGetComboName", and the waits until the
user
enters some data, and then hits ok. The code behind the ok button in the
GetName form does NOT close the form, but does

me.Visiable = false

' at this point, either the user hit ok, or closed the form. If the form is
still open, then user did not cancel, and we assume he hit OK

if isloaded(strF) = true then
' code goes here to example values
strName = forms(strF)!ThenameField
strSex = fomrs(strF)!GenderField
' ok, got our data...lets close the form
docmd.Close acForm,strF
else
' if the form is not open, then user hit the "x", or the cancel
' button on the GetName form. Note that the cancel button on
' the GetName from simply does a docmd.close

msgbox "user canceled"
end if

You also need the code for isloaded. It can be found in tons of examples,
and also in the northwind traders. It is reproduced below just in case
you don't have it:

You can also thus wrap the whole acDialog form code in a function that
returns a value if you want. (I do this for date calendar prompts, and
you thus get re-usable form that can be used anywhere by a simple function).


Function fIsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
If Forms(strFormName).CurrentView <> 0 Then
fIsLoaded = True
End If
End If
End Function
 
Back
Top