Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    delete all the record in the field (Access 2000)

    I have a function that deletes the fied in remote DB. I need however not to delete the field itself, but to delete all the records in this fields.
    Can somebody help me?


    Public Function DeleteField()
    Dim wsp As DAO.Workspace
    Dim StrPassword As String
    StrPassword = "secret"
    Dim tdf As DAO.TableDef
    Dim fld As DAO.field
    Set wsp = DAO.DBEngine.Workspaces(0)
    Dim dbs As DAO.Database
    Set dbs = wsp.OpenDatabase("C:BEstoreBE.mdb", False, False, ";PWD=" & StrPassword)
    Set tdf = dbs.TableDefs("order details")
    Set fld = tdf.Fields("Discount")
    tdf.Fields.Delete fld.Name
    tdf.Fields.Refresh
    dbs.Close
    Set fld = Nothing
    Set tdf = Nothing
    Set dbs = Nothing
    Set wsp = Nothing
    End Function

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: delete all the record in the field (Access 2000)

    To "delete all the records in this fields" does not make sense: a field is a part of a record, not the other way round. Perhaps you want to delete the value of this field in all records, or, put differently, clear this field. For that, you could create the SQL for an update query in code, and execute it:

    Public Function ClearField()
    Dim wsp As DAO.Workspace
    Dim StrPassword As String
    Dim strSQL As String
    StrPassword = "secret"
    Set wsp = DAO.DBEngine.Workspaces(0)
    Dim dbs As DAO.Database
    Set dbs = wsp.OpenDatabase("C:BEstoreBE.mdb", False, False, ";PWD=" & StrPassword)
    strSQL = "UPDATE [order details] SET Discount = Null"
    dbs.Execute strSQL, dbFailOnError
    dbs.Close
    Set dbs = Nothing
    Set wsp = Nothing
    End Function

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: delete all the record in the field (Access 2000)

    Thank you so much ! indeed !!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •