Sub Test()
If AlterFieldType("tablename", "fieldname", "DATE") = True Then
MsgBox "Field type has been succesfully changed!"
Else
MsgBox "Failed!"
End If
End Sub
Function AlterFieldType(strTable As String, strField As String, strNewType As String) As Boolean
Dim db As Object
Dim qryDef As Object
On Error GoTo ErrHandler
' Create a dummy QueryDef object.
Set qryDef = CurrentDb.CreateQueryDef("", "SELECT * FROM " & strTable)
' Add a temporary field to the table.
qryDef.SQL = "ALTER TABLE [" & strTable & "] ADD COLUMN tmpFieldName " & strNewType
qryDef.Execute
' Copy the data from old field into the new field.
qryDef.SQL = "UPDATE DISTINCTROW [" & strTable & "] SET tmpFieldName = [" & strField & "]"
qryDef.Execute
' Delete the old field.
qryDef.SQL = "ALTER TABLE [" & strTable & "] DROP COLUMN [" & strField & "]"
qryDef.Execute
' Rename the temporary field to the old field's name.
CurrentDb.TableDefs("[" & strTable & "]").Fields("tmpFieldName").Name = strField
' Clean up.
ErrHandler:
If Not Err Then
AlterFieldType = True
End If
End Function