Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Userform: what happen to the sub who launched it?

Hello

quick question on userforms. If I have in the following sub something
like

sub LaunchUserform
load userform1
userform1.show
end sub

what happens to the sub once the userform has been loaded and appeared
on the screen? Is the sub terminated? If not at what point does the
sub resumes?

Same thing when I want to unload the userform, from a sub within the
userform. Let's say that in one of the procedures contained in the
userform I have:

sub DoTheStuff
if me.TheValue=1 then
unload me
end if
msgbox "ok"
unload me
end sub

I have the feeling it doesn't always unload the userform after the
unload me, and that it doesn't interupt the sub DoTheStuff at unload
me (I am working on a much more complicated macro, so it's not as easy
to spot what's going on). How can I say both unload the userform and
exit the sub at the same time?

I don't know if this is related but I am also using a userform close
sub which closes a DAO link and cleans up:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)

Is there a chance that this is interfering with how the userform can
be unloaded?

The reason I ask is that sometimes when the userform gives the feeling
it is done and gone, it looks like VBA is still active and the link to
the DB not close (and I can interrupt the code by using the Reset
button in VBA).

So my ultimate question is something like is there an ultimate/propper/
ultra clean syntax or steps to follow to deal with userforms and
loading/unloading them properly?

If anyone has some lights on the topic, would be greatly appreciated.
Thanks in advance
Charles

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Userform: what happen to the sub who launched it?

A sub only ends when the line End Sub is reached (or End is executed which is
pretty much never a good idea).

Subs are like building block that get stacked one on top of the other. The
thread of execution travels up and down the stack. Only the sub or fucntion
on top of the stack can execute code.

So in your code
sub LaunchUserform
load userform1
userform1.show '***
end sub

Where I have indicted *** is where you show the userform. Showing the
userform generates an event that may start code executing in the userform. If
so then that code must complete before the End Sub is reached. The form does
not need to be unloaded for End Sub to be reached, only the event code
generated when the form is shown.

When you execute Unload Me that unloads the form and if you have an unload
event in the form that will execute before any code after the Unload Me line
is executed.

--
HTH...

Jim Thomlinson


"Charles" wrote:

Hello

quick question on userforms. If I have in the following sub something
like

sub LaunchUserform
load userform1
userform1.show
end sub

what happens to the sub once the userform has been loaded and appeared
on the screen? Is the sub terminated? If not at what point does the
sub resumes?

Same thing when I want to unload the userform, from a sub within the
userform. Let's say that in one of the procedures contained in the
userform I have:

sub DoTheStuff
if me.TheValue=1 then
unload me
end if
msgbox "ok"
unload me
end sub

I have the feeling it doesn't always unload the userform after the
unload me, and that it doesn't interupt the sub DoTheStuff at unload
me (I am working on a much more complicated macro, so it's not as easy
to spot what's going on). How can I say both unload the userform and
exit the sub at the same time?

I don't know if this is related but I am also using a userform close
sub which closes a DAO link and cleans up:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)

Is there a chance that this is interfering with how the userform can
be unloaded?

The reason I ask is that sometimes when the userform gives the feeling
it is done and gone, it looks like VBA is still active and the link to
the DB not close (and I can interrupt the code by using the Reset
button in VBA).

So my ultimate question is something like is there an ultimate/propper/
ultra clean syntax or steps to follow to deal with userforms and
loading/unloading them properly?

If anyone has some lights on the topic, would be greatly appreciated.
Thanks in advance
Charles


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wow... Anyone ever seen this happen? Dan R. Excel Discussion (Misc queries) 1 March 16th 07 07:34 PM
Why is that happen ? 0xC00D11CD Excel Worksheet Functions 1 May 22nd 06 01:14 PM
converting ppt to pdf launched from xls pm[_2_] Excel Programming 12 January 6th 06 11:05 PM
converting ppt to pdf launched from xls pm[_2_] Excel Programming 0 January 5th 06 11:33 PM
why would this happen? JENNYC Excel Discussion (Misc queries) 3 December 12th 05 05:56 PM


All times are GMT +1. The time now is 08:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"