Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Kiral Demir   on Mar 09 In MS Office Category.

  
Question Answered By: Silvia Chapman   on Mar 09

Without going too deep, it looks like you've dimensioned the variables
as "local" variables.

Keep in mind that any variables  declared WITHIN a subroutine
are available only to that subroutine.
so, in your Click event, when you have

Dim A as Variant
"A" only has a value until the End Sub statement and is not available
to any other subroutine.

You should move the variable  declarations to immediately following the
Option Explicit
in one of the Modules (preferably the first Module)
Then, be sure to REMOVE any of the Dim statements from the other subs.

Just to test this,
try this:
Option Explicit
Dim T
Sub Test1()
Dim I
For I = 1 To 5
T = I
Debug.Print "Inside Test1, T = " & T & ", I = " & I
Test2
Next I
End Sub
Sub Test2()
Dim I
Debug.Print "Inside Test2, T = " & T & ", I = (" & I & ")"
For I = 1 To 5
Debug.Print "Test Loop: " & T & ": I = " & T & " Test2, I = " & I
Next I
End Sub


then check your Immediate window.
You'll see:

nside Test1, T = 1, I = 1
Inside Test2, T = 1, I = ()
Test Loop: 1: I = 1 Test2, I = 1
Test Loop: 1: I = 1 Test2, I = 2
Test Loop: 1: I = 1 Test2, I = 3
Test Loop: 1: I = 1 Test2, I = 4
Test Loop: 1: I = 1 Test2, I = 5
Inside Test1, T = 2, I = 2
Inside Test2, T = 2, I = ()
Test Loop: 2: I = 2 Test2, I = 1
Test Loop: 2: I = 2 Test2, I = 2
Test Loop: 2: I = 2 Test2, I = 3
Test Loop: 2: I = 2 Test2, I = 4
Test Loop: 2: I = 2 Test2, I = 5
Inside Test1, T = 3, I = 3
Inside Test2, T = 3, I = ()
Test Loop: 3: I = 3 Test2, I = 1
Test Loop: 3: I = 3 Test2, I = 2

Because variables declared "outside" of a sub are available to all subs.
(you may have to declare them Global)
while variables declared "inside" a sub are only available to that sub.

Share: 

 

This Question has 8 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on custom dialogue box variable entry trouble Or get search suggestion and latest updates.


Tagged: