Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

question on scope of a global variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
XL Programmer - 23 Jan 2008 00:47 GMT
I have a user form.  it loads a combo box , with a list of patients,
1 of the options is print a single sheet.  I don't know how to save
the selected value in a global and get that to the module from the
userform.  I tried a public global varible in the userform.  I tried
accessing this from the module like
UserForm1.g_fnameLast and I don't get the value, what am I doing
wrong? the asterisks is where I'm not getting the value.

tia,

-----combo box event in userform1----------
Option Explicit
Public g_rng As Range
Public g_fNameLName As String

Public Sub ComboBox2_change()

   Select Case ComboBox2.Value
   Case Is = "All"
               prntAllPatientsShts
          Case Is = "Exit"

            'do nothing

          Case Else

            g_fNameLName = UserForm1.ComboBox2.Value
               prntSinglePatientSht
                 SingleMonths
   End Select

Unload Me
Me.ComboBox2.Clear
End Sub

-------code where I'm trying to access g_fnamelname-----------------

Sub CpySinglePatientSht()
Dim wb As Workbook
Dim ws As Worksheet
Dim Lname As String
Dim sStr As String

Set wb = ThisWorkbook

   wb.Sheets(2).Copy before:=wb.Sheets(2)
   'copies the control worksheet and puts the copied sheet in front
of it
   Set ws = wb.Sheets(2)
   sStr = UserForm1.g_fNameLName      *********
   Lname = Mid(sStr, InStr(1, sStr, " ") + 1)
   'parses the FName and LName concatenation into _
   just the Lname and renames worksheet
   ws.Name = Lname
End Sub
XL Programmer - 23 Jan 2008 13:05 GMT
This question is  answered.  I figured out what the "scope" problem
was.  It was a simple but annoying.  I set the ws to be the right
sheet and get the global variable which was set up properly but when I
looked at the variable in the debug window there was no value.  A clue
was the drop down list was only 22 or so lines.  What was happening
was I didn't select the active sheet so it was reading values in
column c on the wrong sheet.  the user form is correct.  Thanks
anyway.

> I have a user form.  it loads a combo box , with a list of patients,
> 1 of the options is print a single sheet.  I don't know how to save
[quoted text clipped - 51 lines]
>     ws.Name = Lname
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.