![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
In Access 2000 and later, you can change the field type on the fly: |
#4
| |||
| |||
|
|
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 |
#5
| |||
| |||
|
|
A "Doevents", or some such delay/cleanup, might assist between running code and trying to "execute" something. Who can know what order things are executed in, if you don't place some "Doevents" amongst it. Merely a guess! Chris "Josh" <joshua.paquin (AT) tdsecurities (DOT) com> wrote in message news:ac1dc21f.0411300759.3e7126b4 (AT) posting (DOT) google.com... 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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |