Discussion Locked

MS Access 2000: Change data type w/macro

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Is there a way to open a table in the design view in Access and change the field data type to date through a macro command?

3 replies

by colm_maguire

Hi Zool,

Don't know if you can use a macro but here's some VBA code straight from the Help files that you could modify to set the value if the datas type to Date/Time. You would need to have some way of collecting the name of the field to change (if you want the code to be flexible) such as a combo box on a form that uses a field listing for a table inits drop down menu.

Sub NewField()
Dim dbs As Database, tdf As TableDef
Dim fld As Field

' Return reference to current database.Set dbs = CurrentDb
' Return reference to Employees table.
Set tdf = dbs.TableDefs!Employees
' Create new Field object.
Set fld = tdf.CreateField("SSN#")
' Set Type and Size properties of Field object.
fld.Type = dbText
fld.Size = 11' Append field.
tdf.Fields.Append fld
' Enumerate all fields in Fields collection of TableDef object.

For Each fld in tdf.Fields
Debug.Print fld.Name
Next fld
Set dbs = Nothing
End Sub

Any reason why you don't just do it manually?

by zool326

Trying not to do it manually, to avoid having to do the user training. Thanks for you help!

This discussion is closed to new replies.