I am trying to use this code to change data type at run time but I am getting "SUB OR FUNCTION NOT DEFINED" error when the code is executed, please advise!!!
the problem start at AlterTempField " &NewDataType " is where I am getting the "SUB OR FUNCTION NOT DEFINED".
Code:
Option Explicit
'*****************************************************************
' The AlterFieldType Sub procedure requires three string
' parameters. The first string specifies the name of the table
' containing the field to be changed. The second string specifies
' the name of the field to be changed. The third string specifies
' the new data type for the field.
'*****************************************************************
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 arcusts")
' 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
the problem start at AlterTempField " &NewDataType " is where I am getting the "SUB OR FUNCTION NOT DEFINED".