Changing the Caption of a Label inside nested VBA (1 Viewer)

GregoryWest

Registered User.
Local time
Today, 00:50
Joined
Apr 13, 2014
Messages
161
OK I thought this would be easy, go figure it isn't.


I need to change a label of a VBA form. There are a few check boxes for work to be done a big label box Named 'CompMsg' (this is what I want to change). and a button to get the whole batch running.....


When I press the button the called VBA contains the lines:
Code:
Private Sub LoadData_Click()
DoCmd.SetWarnings False
CompMsg.Caption = "Hi there Hi There..."
This works just fine. Below the change of the label there is a bunch of connands testing various conditions and executing other VBA cide. Something like:
Code:
If Me.Load168 Then
  Call RunLoad(168)
End If
Now on one of these VBA subs, inside a loop another VBA sub is called and again one more time:
Code:
call sub1(value)


private sub sub1(value1 as integer)
do while ......
  call sub2(value2)
...
loop
end sub


private function sub2(cntr as integer)
....   do some stuff....   and then
  msgline = ("Currently " & Left(Str((curr_rec / totrecs)), 6) & "% Done.")
  If curr_rec = (Int(curr_rec / 10) * 10) Then CompMsg.Caption = msgline
endsub
This change of caption gives me a runtime error 424 object not defined.
Now the VBA that the button calls is located under the "Build Event..." Sub1 and Sub2 are located in a common container of VBA code as it is called from various places.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:50
Joined
May 7, 2009
Messages
19,247
use the instance of the form:

… Then Forms!FormName!CompMsg.Caption = msgline
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:50
Joined
Sep 21, 2011
Messages
14,317
Sub2 is a function so that could pass the msgline back to Sub1.

If you pass the frm object through as far as sub1, then you could set the caption there, otherwise pass it on to sub2, though that seems very laborious.?

Code:
Call RunLoad(168, Me)
................
Sub RoutineThatCallsSub1(frm as Form)
Call Sub1(Value, frm)
End Sub

Sub Sub1(Value as Integer, frm as Form)
Dim strCaption as String
strCaption = Sub2


frm.CompMsg.Caption = sub2
End Sub

or continue passing it on down the chain.?

Can't help feeling a Global variable would be a better option? then set caption after the RunLoad statement, having set the global variable in Sub2?
 

GregoryWest

Registered User.
Local time
Today, 00:50
Joined
Apr 13, 2014
Messages
161
Thank you thanks you thank you. That worked GREAT! I am still tripping all over keywords like FORM or FORMS and is it a . between works or a !


Your solution worked great!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:50
Joined
May 7, 2009
Messages
19,247
we are happy to help.
 

Users who are viewing this thread

Top Bottom