Object reference not set to an instance of an object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Abhiraj Chauhan
    New Member
    • Oct 2008
    • 19

    #1

    Object reference not set to an instance of an object

    here are code in vb.net when ever i try to delete entry... this error occurs . Null reference Exception was unhandled....Us e new key word to create an object reference.Plz if anyone can help how can i solve this problem.

    Code:
    Private Sub Deldata(ByRef dfname As String)
            Dim Dc As DAO.Recordset
            CurDb = CurrentDb
            Dim SSTR As String
            Dc = CurrentDb.OpenRecordset("tableName", DAO.RecordsetTypeEnum.dbOpenDynaset)
            SSTR = "Cto = '" & dfname & "'"
            Dc.FindFirst(SSTR)
            If Not (Dc.NoMatch) Then
                MsgBox("Column being used in other entries. Can't delete", 64, "Abhiraj")
                DelFlag = True
                Dc.Close()
                Exit Sub
            End If
            Dim ds As DAO.Recordset
            Dim Searchstr As String
            ds = CurDb.OpenRecordset("Columns", DAO.RecordsetTypeEnum.dbOpenDynaset)
            Searchstr = "CName = '" & dfname & "'"
    
            ds.FindFirst(Searchstr)
            If ds.NoMatch Then
                MsgBox("No such column found", 11, "Abhiraj")
                ds.Close()
                Exit Sub
            End If
            If ds.Fields(4).Value = 0 And ds.Fields(5).Value = 0 Then
                MsgBox("Column being used in other entries. Can't delete", 64, "Abhiraj")
                DelFlag = True
                Exit Sub
            End If
    
            ds.Delete()
            ds.Close()
            Dc.Close()
        End Sub
    Last edited by Curtis Rutland; Oct 1 '08, 01:34 PM. Reason: Added Code Tags - Please surround your code with [CODE] and [/CODE]
  • AlmightyJu
    New Member
    • Sep 2008
    • 7

    #2
    Any idea which line is causing it to say that?

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by AlmightyJu
      Any idea which line is causing it to say that?
      Once you get the line number, you can then see which objects on that line are being dereferenced. The exception is thrown because one of the objects being dereferenced is not yet initialized.

      Comment

      • Abhiraj Chauhan
        New Member
        • Oct 2008
        • 19

        #4
        Originally posted by r035198x
        Once you get the line number, you can then see which objects on that line are being dereferenced. The exception is thrown because one of the objects being dereferenced is not yet initialized.
        Thank you replying, sorry to be late..this is the line that is Causing me so much of problems....

        Dc = CurrentDb.OpenR ecordset("table Name", DAO.RecordsetTy peEnum.dbOpenDy naset)

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by Abhiraj Chauhan
          Thank you replying, sorry to be late..this is the line that is Causing me so much of problems....

          Dc = CurrentDb.OpenR ecordset("table Name", DAO.RecordsetTy peEnum.dbOpenDy naset)
          Now read my response above again.

          Comment

          Working...