Hi,
I am trying to write a function in a module in MS Access 2000 that
will change the data type of a field called 'Start' in table
'bo_cpm_CS01ALL'. Here is the code that I have done so far but when I
run it nothing happens...no errors or changes to the table. The code
finds the table and field, creates a new field called 'temp' then
copys 'Start' to 'temp' then deletes 'Start' and renames 'temp'. The
field 'Start' has data type dbDouble.
Any help would be great!!
Public Function ChangeFieldType()
'Purpose: Changes a field's datatype
Dim db As DAO.Database
Dim tdef As DAO.TableDef 'Table to modify
Dim fldOld As DAO.Field 'Field to modify
Dim fldNew As DAO.Field 'Destination field
Dim Property As DAO.Property 'Field property
Dim strSQL As String 'SQL string to move the data
Set db = CurrentDb
'Get the table definition
Set tdef = db.TableDefs("bo_cpm_CS01ALL")
'Get the original field
Set fldOld = tdef.Fields("Start")
'Create the new field
Set fldNew = tdef.CreateField("temp", dbDate)
'Append the field
tdef.Fields.Append fldNew
'Copy the data
strSQL = "UPDATE bo_cpm_CS01ALL Set bo_cpm_CS01ALL.Start = temp"
db.Execute strSQL, dbFailOnError
'Delete the original field
tdef.Fields.Delete "Start"
'Rename the new field
fldNew.Name = "Start"
End Function