I found this code that will do what I am needing posted by DougP. Thanks Doug,
How do I place this code in a sub routine and How do I put the last piece of info in a Debug window?
Sub AlterFieldType(TblName As String, FieldName As String, NewDataType As String)
Dim db As Database
Dim qdf As QueryDef
Set db = CurrentDb()
' Create a dummy QueryDef object.
Set qdf = db.CreateQueryDef("", "Select * from Table1"
' Add a temporary field to the table.
qdf.SQL = "ALTER TABLE [" & TblName & "] ADD COLUMN AlterTempField " & NewDataType
qdf.Execute
' Copy the data from old field into the new field.
qdf.SQL = "UPDATE DISTINCTROW [" & TblName & "] SET AlterTempField = [" & FieldName & "]"
qdf.Execute
' Delete the old field.
qdf.SQL = "ALTER TABLE [" & TblName & "] DROP COLUMN [" & FieldName & "]"
qdf.Execute
' Rename the temporary field to the old field's name.
db.TableDefs("[" & TblName & "]".Fields("AlterTempField".Name = FieldName
' Clean up.
End Sub
------------------------------------------
Put the following a the debug window
AlterFieldType "Table1", "Employee", "LONG"
How do I place this code in a sub routine and How do I put the last piece of info in a Debug window?
Sub AlterFieldType(TblName As String, FieldName As String, NewDataType As String)
Dim db As Database
Dim qdf As QueryDef
Set db = CurrentDb()
' Create a dummy QueryDef object.
Set qdf = db.CreateQueryDef("", "Select * from Table1"
' Add a temporary field to the table.
qdf.SQL = "ALTER TABLE [" & TblName & "] ADD COLUMN AlterTempField " & NewDataType
qdf.Execute
' Copy the data from old field into the new field.
qdf.SQL = "UPDATE DISTINCTROW [" & TblName & "] SET AlterTempField = [" & FieldName & "]"
qdf.Execute
' Delete the old field.
qdf.SQL = "ALTER TABLE [" & TblName & "] DROP COLUMN [" & FieldName & "]"
qdf.Execute
' Rename the temporary field to the old field's name.
db.TableDefs("[" & TblName & "]".Fields("AlterTempField".Name = FieldName
' Clean up.
End Sub
------------------------------------------
Put the following a the debug window
AlterFieldType "Table1", "Employee", "LONG"