well first if you read this:
I also realized that all this is a public varialbe, which I have right now and I am trying to get rid of it:
VBA:
Public objFirstUserForm As Object
I am in the process of trying to get ride of as many Public Variables as I can because I read you should keep them to a minimum. I used to use Public Variables for everything. I started with close to 50 public Variables but now I am down to about 20. I want to get it down to about 5
The answer actually looped me back to the way I was originally doing it with a Public Variable. I don't want to use a Public Variable if I don't have to. I sent a cleaned up version of my code also here:
[VBA]
Sub StartSalesReport(ByVal lngPivotData As Long, Optional ByVal objUserForm As Object, _
Optional ByVal stgReportName As String)
'Testing Version - Trying to simplify sub
'***If objUserForm is used then stgReportName needs to be blank***
'***If stgReportName is used then objUserForm needs to be = Nothing***
'***Both stgReportName = "" and objUserForm is nothing can't happen at the same time***
CreateTab:
If Not objUserForm Is Nothing Then 'stgReportName = "" and not objUserForm is Nothing
objUserForm.Show
stgMyInput = objUserForm.ReportName
If (stgMyInput) = "" Then 'Test if user left name blank
objUserForm.Hide
DoEvents
With frmError00_00_03 'Show error form and restart sub if user clicks Name Report
Set .objFirstUserForm = objUserForm
.Show
End With
Exit Sub
End If
If i = 0 Then 'Test if user selected at least one data value
MsgBox "You need to select at least one value to view!"
Goto CreateTab 'If i = 0 then restart the sub
End If
Else 'objUserForm is Nothing and Not stgReportName = ""
stgMyInput = stgReportName
End If
'Test if another sheet with the same name exists
If SheetExists(stgMyInput) Then
If Not objUserForm Is Nothing Then
objUserForm.Hide
DoEvents
End If
frmError00_00_02.Show 'Show error form and restart sub if user clicks Rename Report
Exit Sub
End If
TurnOffFeatures 'Turns off screen updating and sets formulas to manual
Set wsWorking = Worksheets.Add(, wsData, 1) 'Creates Worksheet for Pivot Table
wsWorking.Name = stgMyInput 'Names Pivot Table tab from Variable stgMyInput
ptBegin lngPivotData 'Creates PivotTable with Data from
End Sub
[/VBA]
and the form:
[VBA]Public objFirstUserForm As Object 'This is what I am trying to get rid of
Private Sub cmdEmailDeveloper_Click()
'If User Clicks this button it will email developer about the error recieved
Me.Hide
DoEvents
emBugReport " - Error 00-00-03"
End
End Sub
Private Sub cmdFormCancel_Click()
Unload Me
End
End Sub
Private Sub cmdNameReport_Click()
'If User Clicks this button then it will rerun the StartSalesReport sub
Unload Me
DoEvents
StartSalesReport finalrow(wsData) - 1, objFirstUserForm
End Sub[/VBA]
anyway doing it this way, I set up a watch and for some reason after the frmError00_00_03 shows and I click on the cmdNameReport button and StartSalesReport restarts objFirstUserForm = Nothing