Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Text field in a table (Access 2000)

    Can you help me find in Visual basic a command converting on the fly a text field in a table into a number field with 2 decimal places? the table is called Crates and the field is called "brooks". The point is that i do not to delete the field, just alter it.I have begun in the following way :
    Dim wsp As DAO.Workspace
    Dim dbs As DAO.Database
    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field
    Dim prp As DAO.Property
    Set wsp = DAO.DBEngine.Workspaces(0)
    Set dbs = wsp.curentdbs
    Set tdf = dbs.TableDefs("Crates")

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

    Re: Text field in a table (Access 2000)

    As you already know from <!t>[Post: 604,581]<!/t>, you cannot use DAO methods to change the data type of field, you must use SQL for that. Try this:

    Sub ChangeField()
    Dim strSQL As String
    Dim dbs As DAO.Database

    On Error GoTo ErrHandler

    Set dbs = CurrentDb
    strSQL = "ALTER TABLE Crates ALTER COLUMN Brooks FLOAT"
    dbs.Execute strSQL, dbFailOnError

    ExitHandler:
    Set dbs = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

Posting Permissions

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