John said:
Gilgamesh said:
Can anyone tell me if once a form has been shown whether control can
be
thrown back to the calling code while keeping the form displayed?
What I am trying to do is just bring up a form to display progress
messages
to the user while the main code is running. So no user interaction is
desired with the form itself.
i.e
MyForm.Show
.
.
MyForm.LabelMessage.Caption = "Starting Section 2"
MyForm.Repaint
.
.
Unload MyForm
I know that I could put processing code in the form itself but due to
parameters being passed into my module with the MyForm.Show command
this
is
not practical.
Thank You
Thanks for answering - I have a few comments below.
Gilgamesh,
To answer your question, yes, control can be turned over to another
procedure with the form still displayed. You simply call the other
procedure in the code behind the form. The form will remain visible
until you unload it.
I was aware of that but it seems I didn't explain myself clearly.
I need to throw control back to the line following the MyForm.Show
command.
This command is in a procedure that has parameters passed to it and
passing
control to another procedure via a call from the form will lose this
information (Unless I can pass parameters to the form and than back to
another procedure ???? )
However, if all you want to do is to display progress for the user,
that
can be done in a couple of places. The one I always use, particularly
for complex or long running macros, is to show progress in the window
caption. The general syntax is:
application.ActiveWindow.Caption = ["your progress message here"]
For longer running processes, I include a calculation that displays a
percentage. For example, if the code has a loop that cycles through all
tasks, I calculate and display a percentage based on how many tasks
have
been processed. That way the user not only knows the macro is running
but also has an idea on how it is progressing.
I like using the controlbar widget for this as it gives a nice graphical
representation of the percentage (and doesn't require a form repaint when
it
is updated).
Your suggestion of using the active window caption seems to be the only
option available. Thanks.
Hope this helps.
John
Project MVP
Gilgamesh,
I'm still not sure I fully understand what you want to do but let me
take a stab.
I have a few complex macros that start out with a one procedure that
does some basic checks on the file (e.g. is it a valid file, does it
have tasks, etc.). That procedure then calls a uerform with the Show
command. Various parts of the form are populated with data from the file
using the syntax:
Private Sub UserForm_initialize()
The form then takes input from the user and checks it for validity (e.g.
valid dates, valid string entries, etc.). Once the form data has been
entered, (or the default form data accepted), by the user, the form code
calls the main procedure with the syntax:
[procedure name] ByVal [parameters from the form]
The main procedure then operates on the data. During operation, the main
procedure sends information back to the form which contains a progress
statement. When all processing is done the form is unloaded and the main
procedure does some cleanup steps and closes.
Now, I don't know is this is similar to what you want to do, but it does
illustrate a multi-tiered procedure with form structure.
Hope this helps.
John
Project MVP
Hello,
I appreciate your assistance but I did understand this as a possible
approach but unfortunately it doesn't work in my circumstance. Here is an
outline of what I am trying to do.
Sub MySub(oObj as object, sStr as string, bBool as boolean)
.
' I have some processing logic in here using the parameters passed into this
procedure to determine if I need to display a form or not.
.
If FormNeeded then
frmMyForm.Show ' I do not want any processing done in the form at all and
control to fall straight through to the next line
.
' Data updates on the form are determined in this code here using the oObj,
sStr, and bBool parameters
.
frmMyForm.Hide
unload MyForm
End If
End Sub
Unless it is possible to pass the oObj, sStr, and bBool parameters to the
form so that the MyForm_Initialize procedure can pass them back to another
procedure then the flow you are suggesting does not work for me.
But there is good news. This was not the only forum I posed the question to
and I got a response on the other that does exactly what I want. Using the
form as modeless like the code below passes control straight to the MsgBox
command as soon as the form is displayed. I would classify this as a
win/win where everyone learned something
Thanks again.
UserForm1.Show (vbModeless)
MsgBox "Hi there"
UserForm1.hide
Unload UserForm1