Results 1 to 4 of 4

Thread: Delete *fields* from a table **RESOLVED**

  1. #1

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545

    Delete *fields* from a table **RESOLVED**

    Hi,

    I need a way to delete a field from a table. Is there any SQL command that can do this, or would I have to use ADO, or something else?

    These fields are part of an 'extra data' table which my program reads and lists all the fields so the user can add data that isnt in any existing table.

    By the way, I am using this code to Add a field to a table (which works great), but I can't figure out how to modify it so that it will let me delete a field. Anyone know?

    VB Code:
    1. Public Sub CreateADOField(DbFile As String, strTablename As String, _
    2.     strFieldName As String, Style As Variant, Optional intLenght As Integer)
    3.  
    4.     On Local Error Resume Next
    5.    
    6.    ' Add to references
    7.    ' Microsoft ADO Ext. 2.x for DDL and Security
    8.    
    9.     Dim cat     As New ADOX.Catalog
    10.     Dim tbl     As New ADOX.Table
    11.     Dim Col     As New ADOX.Column
    12.  
    13.     cat.ActiveConnection = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
    14.          DbFile & ";"
    15.  
    16.     Col.name = strFieldName
    17.     Col.Attributes = adColNullable
    18.     If intLenght > 0 Then Col.DefinedSize = intLenght
    19.     Col.Type = Style
    20.     cat.Tables.Item(strTablename).columns.Append Col
    21.     cat.Tables.Item(strTablename).columns.Item(strFieldName).Properties("Jet OLEDB:Allow Zero Length") = True
    22.    ' use field properties to set parameters
    23.     Set cat = Nothing
    24.    
    25. End Sub
    Last edited by ae_jester; Jun 10th, 2003 at 11:44 AM.

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    VB Code:
    1. Sub AlterTableX2()
    2.  
    3.     Dim dbs As Database
    4.  
    5.     ' Modify this line to include the path to Northwind
    6.     ' on your computer.
    7.     Set dbs = OpenDatabase("Northwind.mdb")
    8.  
    9.     ' Delete the Salary field from the Employees table.
    10.     dbs.Execute "ALTER TABLE Employees " _
    11.         & "DROP COLUMN Salary;"
    12.  
    13.     dbs.Close
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  3. #3

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    Yah thats it! I learned in it first year, but forgot how. Thanks

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Glad to have helped...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

Posting Permissions

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



Click Here to Expand Forum to Full Width