Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a variable to a form... stumped!

Status
Not open for further replies.

realtree

Technical User
Aug 5, 2003
53
0
0
CA
I'm REALLY stumped this time.
It seems like my UserForm_Initialize() sub can't see my variable from the general declarations in the procedure that loads the form.

Schedule worksheet:
Code:
Dim lngRow As Long
    
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    lngRow = Target.Range.Row
    MsgBox lngRow
    Load formScore
    formScore.Show
    Unload formScore
    Worksheets("Schedule").Range("I1").Activate
End Sub

formScore:
Code:
Private Sub UserForm_Initialize()
    MsgBox lngRow
End Sub

The first MsgBox dislplays the row number, but the second one is blank, obviously not seeing the 'global' variable...
I've looked all over to find out why. Everywhere they simply say declare it in the general section in the module that loads the form... anybody see the problem?
 
Hi trefrog,

If you want a variable to be visible outside its module (i.e. global) you need to declare it as Public.

If the variable relates to your userform, however, it would be better declared in the userform.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Okay.. I have to reference the variable 'from the top'.
Worksheets("Schedule").lngRow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top