PC Review


Reply
Thread Tools Rate Thread

Call a sub in a modeless userform from a code module?

 
 
fedude
Guest
Posts: n/a
 
      29th May 2009
I have a long calculation and I created a userform (CHandicaps) with a
progress-bar. In CHandicaps, I created a routing to update the progress bar
(UpdateProgress).

So when my calculation begins, I show the userform:

CHandicaps.Show vbModeless

Now during the long calculation, I want to call the UpdateProgress function
in the userform.

This seems simple, but I've been banging around with this for a long time
and cannot get my head around how to interact with a form "from a module".
Color me lost....

Do I need to pull the UpdateProgress code out of the userform and put it in
my calculation? If so how do I reference a field in the userform?

Any help would be appreciated..
 
Reply With Quote
 
 
 
 
r
Guest
Posts: n/a
 
      29th May 2009
'Userform class module
'Userform1 with ScrollBar1
Option Explicit

Private Sub UserForm_Initialize()
Me.ScrollBar1.Min = 0
Me.ScrollBar1.Max = m
End Sub


'standard module
Option Explicit

Public m As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub Test()
Dim lTop As Long, i As Long
lTop = 100
m = lTop
UserForm1.Show vbModeless

For i = 0 To lTop
addOne i
'...
Sleep 100
DoEvents
'...
Next

Unload UserForm1
End Sub

Sub addOne(i As Long)
UserForm1.ScrollBar1.Value = i
End Sub

regards
r

--
http://excelvba.altervista.org/blog/...ternative.html


"fedude" wrote:

> I have a long calculation and I created a userform (CHandicaps) with a
> progress-bar. In CHandicaps, I created a routing to update the progress bar
> (UpdateProgress).
>
> So when my calculation begins, I show the userform:
>
> CHandicaps.Show vbModeless
>
> Now during the long calculation, I want to call the UpdateProgress function
> in the userform.
>
> This seems simple, but I've been banging around with this for a long time
> and cannot get my head around how to interact with a form "from a module".
> Color me lost....
>
> Do I need to pull the UpdateProgress code out of the userform and put it in
> my calculation? If so how do I reference a field in the userform?
>
> Any help would be appreciated..

 
Reply With Quote
 
fedude
Guest
Posts: n/a
 
      30th May 2009
Thanks Leith. That did the trick.

I was all good with what you wrote except for the fact that my sub was
private. Your comment about the sub being "visible" triggered me to remove
the "Private" from the sub and voila.....Success.

Thanks!

"Leith Ross" wrote:

>
> fedude;363036 Wrote:
> > I have a long calculation and I created a userform (CHandicaps) with a
> > progress-bar. In CHandicaps, I created a routing to update the
> > progress bar
> > (UpdateProgress).
> >
> > So when my calculation begins, I show the userform:
> >
> > CHandicaps.Show vbModeless
> >
> > Now during the long calculation, I want to call the UpdateProgress
> > function
> > in the userform.
> >
> > This seems simple, but I've been banging around with this for a long
> > time
> > and cannot get my head around how to interact with a form "from a
> > module".
> > Color me lost....
> >
> > Do I need to pull the UpdateProgress code out of the userform and put
> > it in
> > my calculation? If so how do I reference a field in the userform?
> >
> > Any help would be appreciated..

>
> Hello fedude,
>
> Provided the user form is visible and the procedure is in General code
> section, prefix the name of the procedure with the user form's name. In
> this example the user form has a combo box. In the general code section
> of "UserForm1" is defined a procedure to load the combo box
> "ComboBox1".
>
> Public Sub LoadComboBox()
> With ComboBox1
> .Clear
> For I = 1 to 10
> .AddItem "Item " & I
> Next I
> End With
> End Sub
>
> This code is in a standard VBA module. The user form must be visible
> when you run this code or it will throw an error.
>
> Sub Test()
> UserForm1.LoadComboBox
> End Sub
>
> SIincerely,
> Leith Ross
>
>
> --
> Leith Ross
>
> Sincerely,
> Leith Ross
>
> 'The Code Cage' (http://www.thecodecage.com/)
> ------------------------------------------------------------------------
> Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
> View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=101813
>
>

 
Reply With Quote
 
fedude
Guest
Posts: n/a
 
      30th May 2009
Thanks r,

When I saw your sub "addOne" was not private triggered me to remove the
private attribute and make it available. Voila, I was in business.

Thanks for the help!

 
Reply With Quote
 
fedude
Guest
Posts: n/a
 
      30th May 2009
Thanks r,

When I saw your sub "addOne" was not private triggered me to remove the
private attribute and make it available. Voila, I was in business.

Thanks for the help!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
code for impoting userform and module baha17@gmail.com Microsoft Excel Programming 0 2nd Oct 2009 05:59 PM
Refer to control on userform from code module =?Utf-8?B?RGFsZSBGeWU=?= Microsoft Excel Programming 1 6th Sep 2007 03:14 PM
Code in userform/worksheet vs. in Module davegb Microsoft Excel Programming 2 19th Jun 2006 04:17 PM
How to call a sub from UserForm Module Myles Microsoft Excel Programming 2 31st Mar 2006 04:40 AM
Calling procedure from UserForm Code Module rob nobel Microsoft Excel Misc 4 2nd Feb 2004 09:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:09 PM.