Transferring Variables among Subs


Posted by k.p.b on February 28, 2001 2:19 PM

I want to call up one Sub from another and still use variables from the first. Since I'm using a button and the button calls up the Sub I can't get it to let me use "Public variable as String". This causes a script error when I try to execute the second Sub.



Posted by David Hawley on February 28, 2001 3:16 PM


Hi k.p.b

You have to place the Dim statement at the very top of the NORMAL module like this.

Private Sub CommandButton1_Click()
MyName = "HH"
Run "UpDate"
End Sub


THEN IN A NORMAL MODULE:

Option Explicit
Public MyName As String
Sub UpDate()
MsgBox MyName
End Sub

Dave

OzGrid Business Applications