Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datetimepicker dispose error 1

Status
Not open for further replies.

jbehrne

Programmer
Dec 18, 2002
484
US
Hi all,

I have created a form that is used to select a date for reporting purposes. The user selects the date from a datetimepicker and then the date is passed to a stored procedure to be saved in a sql server. After the date is inserted the form is closed and disposed off. However, after the form closes and before my reports are printed I get the following error:

Code:
Cannot access a disposed object.
Object name: 'DateTimePicker'.

System.ObjectDisposedException was unhandled
  Message="Cannot access a disposed object.\r\nObject name: 'DateTimePicker'."
  Source="System.Windows.Forms"
  ObjectName="DateTimePicker"
  ...

Here is the code for the datetimepicker event:

Code:
Call ClearTable(Servername)
        Call InsertSelectedDate(Servername)
        Me.Focus()
        If MsgBox("You have selected " & Me.DateTimePicker1.Value & " as the report date." & vbCrLf & "Is this correct?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Confirm Date") = MsgBoxResult.No Then
            Exit Sub
        End If

        Try
            Me.Close()
            Me.Dispose()
        Catch ex As Exception
            MsgBox("Error: " & Err.Number & vbCrLf & "Desc: " & Err.Description)
        End Try

Any help would be greatly appreciated! Thanks,

jbehrne

If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Nevermind... The problem was that i was using the .datechanged event instead of .dateselected! That cleared up the problem!

If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Thank you.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top