RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
I have a userform which when I click on a label launches another userform. On this second userform I want to pass data from a worksheet through a public property.
I have done this before but it does not work in this example and I haven't the foggiest why not?
*I click on label named ICPSOLIDS and it calls a new instance of A1_ICPSUMMARY
And then the code for the userform contains the setting of the Worksheet property (amongst others). But I get an "Object variable not set" when it tries to pass the 'mwksWorksheet' to a function. I can fix the problem (see comment in code) but I don't see why I have to (I want this userform to accept other worksheets as well).
I have done this before but it does not work in this example and I haven't the foggiest why not?
*I click on label named ICPSOLIDS and it calls a new instance of A1_ICPSUMMARY
Code:
Private Sub ICPSOLIDS_Click()
Dim frm As A1_ICPSUMMARY
'--create a new instance of charting userform A1_ICPSUMMARY
Set frm = New A1_ICPSUMMARY
'--pass worksheet with headers and data to public property of frm
Set frm.Worksheet = ThisWorkbook.Sheets("212-R365")
A1_ICPSUMMARY.Show vbModeless
End Sub
And then the code for the userform contains the setting of the Worksheet property (amongst others). But I get an "Object variable not set" when it tries to pass the 'mwksWorksheet' to a function. I can fix the problem (see comment in code) but I don't see why I have to (I want this userform to accept other worksheets as well).
Code:
Option Explicit
'--userform module variables
Private msAxisTitle As String
Private msDataIdentifier As String
Private mrXValues As Range
Private mrYValues As Range
Private miCount As Integer
Private mwksWorksheet As Worksheet
'--public properties
Public Property Let AxisTitle(sAxisTitle As String)
msAxisTitle = sAxisTitle
End Property
Public Property Let DataIdentifier(sDataIdentifier As String)
msDataIdentifier = sDataIdentifier
End Property
Public Property Let Count(iCount As Integer)
miCount = sCount
End Property
Public Property Set XValues(rXvalues As Range)
Set mrXValues = rXvalues
End Property
Public Property Set YValues(rYvalues As Range)
Set mrYValues = rYvalues
End Property
Public Property Set Worksheet(wks As Worksheet)
Set mwksWorksheet = wks
End Property
'userform activates a calls MakeChartSummary()
[COLOR=#222222][FONT=Verdana]'--privateprocedures
Private Sub MakeChartSummary()
'--creates a new chart, makes a jpg image and displays the image
Dim MyChart As Chart
Dim dblZoomSave As Double
Dim ImageName As String
Dim sDataIdentifier As String
Dim lColNdx As Long
Dim MaxChartNumber As Double
Dim MinChartNumber As Double
Dim Padding As Double
sDataIdentifier = msDataIdentifier
'Code works if I uncomment here - but why do I need to as mwksWorksheet shouldbe set by the
'public property
'Set mwksWorksheet = ThisWorkbook.Worksheets("212-R365")
'Code fails in the sGetChartParameter function as mwksWorksheet is not defined.
msAxisTitle = sGetChartParameter(wks:=mwksWorksheet, _
sDataIdentifier:=sDataIdentifier, _
sParameter:="Axis Title")
[/FONT][/COLOR]