Launching a report form a listbox using vb .net

Overtonp
Overtonp used Ask the Experts™
on
I have an application that I'd like to add the ability to launch reports from a listbox.  All it contains is a simple listbox and a button that launches another form containing the crystalreportviewer .net component.  The code below is what I have done so far.

I created the list box and added an item to the list.  I then created the run report button which launches a new form containing the crystal report viewer, and attempts to apply a .reportsource property based on what item in the listbox is selected.
 
This launches the new report form, however the report source property does not carry over, instead  report simply comes up blank.  Am I using the .reportsource property correctly?

Public myCaller As New ReportForm 'name of the second form being launched
...

 Private Sub Button1_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
        Handles Button1.Click

        If Reportbox.SelectedItem = Nothing Then
            MsgBox("Please select a report to run")
            Exit Sub
        End If

        If Reportbox.SelectedItem.Equals(repname1) Then 
            myCaller.CrystalReportViewer1.ReportSource = "C:\Documents and Settings\overtonp\Desktop\Samco Jobs\Crystal Reports\pow103_CUSTOM.rpt"
        End If
       
        If myForm Is Nothing Then
                myForm = New Form1
        End If
        myForm.Show()      
    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
You have two different variable names involved..."myCaller" and "myForm"!

Try using just "myCaller":
    Public myCaller As New ReportForm 'name of the second form being launched

    Private Sub Button1_Click( _
         ByVal sender As System.Object, _
         ByVal e As System.EventArgs) _
           Handles Button1.Click

        If Reportbox.SelectedItem = Nothing Then
            MessageBox.Show("Please select a report to run")
        Else
            If IsNothing(myCaller) OrElse myCaller.IsDisposed Then
                myCaller = New ReportForm
            End If
            If Reportbox.SelectedItem.Equals(repname1) Then
                myCaller.CrystalReportViewer1.ReportSource = "C:\Documents and Settings\overtonp\Desktop\Samco Jobs\Crystal Reports\pow103_CUSTOM.rpt"
            End If
            myCaller.Show()
        End If
    End Sub

Open in new window

Author

Commented:
That did it,  was calling the incorrect form.  Couldn't find anything wrong... thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial