Pass value froma form to another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JustRun
    New Member
    • Mar 2008
    • 127

    Pass value froma form to another

    hi,

    I have a problem with passing the value from a Form that "user should choose a start date and end date" to a Form that display the result in a Crystal Report Form

    Actually it gives this error at runtime:
    "SqlDateTim e overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM"

    Code:
    'The form that dates will be picked from 
    
    Public Class frmBuyDate
        Public dateStart As String
        Public dateEnd As String
    
        Private Sub btnShowReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowReport.Click
            dateStart = dpStart.Value.ToShortDateString
            dateEnd = dpEnd.Value.ToShortDateString
            'MessageBox.Show(dateStart.ToString())
            Dim objBuyRprt As New frmBuyRprt()
            objBuyRprt.ShowDialog()
        End Sub
    End Class

    Code:
    'Here, both 'dateStart' and 'dateEnd' are Null !!!!!! This is the thing I want to know , WHY 
    I always used to do this with C# and it works, whats wrong here?
    
    Public Class frmBuyRprt
    
        Private Sub frmBuyRprt_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
           Try
                Me.BUYSTableAdapter.FillByDate(PHARMACYDBDataSet.BUYS, Convert.ToDateTime(frmBuyDate.dateStart), Convert.ToDateTime(frmBuyDate.dateEnd))
    
                Dim objBuyRprt As New CrystalReport1
                objBuyRprt.SetDataSource(PHARMACYDBDataSet)
                crvBuy.ReportSource = objBuyRprt
            Catch ex As Exception
                MessageBox.Show(ex.ToString())
    
            End Try
          
        End Sub
    End Class

    Code:
    'The Dataset Query'
    
    SELECT  Med_ID, Med_Date, Med_Cat, Med_Name, Med_Qty, Med_Price, Med_TotalPrice
    FROM         BUYS
    WHERE     (D2 >= @startDate) AND (D2 <= @endDate)
    ORDER BY D2 DESC
    I tested the query and it works perfect, also the form of pickers works perfect.
    Thanks.
  • Enij
    New Member
    • Apr 2009
    • 13

    #2
    I'm not sure if I'm following this correctly, but...

    On your second code example, line 8, you're trying to use frmBuyDate, but I can't see any code where this class has been instantiated:

    Code:
    Dim myBuyDate As New frmBuyDate
    
    myBuyDate.ShowDialog()
    
    ' test dialog result here
    If myBuyDate.DialogResult = DialogResult.OK Then
    ' use myBuyDate.dateEnd / etc here
    End If
    
    ' >> dereference form dialog
    If no form has been instantiated, everything will be Nothing.

    From the code provided, that's what it looks like to me anyway ;)

    Comment

    Working...