From: exebat on
Is there a way to create a Calculated field in Access 2010 table using
VBA ?

I can create any type of field but cant find the way to create new
Calculated field type.
From: Arvin Meyer [MVP] on
"exebat" <srdjan.vasiljevic(a)gmail.com> wrote in message
news:a326eef0-8deb-4222-8828-2fc91baf0d26(a)y17g2000yqd.googlegroups.com...
> Is there a way to create a Calculated field in Access 2010 table using
> VBA ?
>
> I can create any type of field but cant find the way to create new
> Calculated field type.

My 2010 machine is getting it's webcam repaired so I couldn't check this but
MVP Crystal Long wrote some sample code for you:

Sub CreateCalculatedField()
'Crystal 100421

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Dim sTblNm As String
Dim sFldNm As String
Dim i As Integer

i = 0

On Error GoTo Proc_Err

sTblNm = "People"
sFldNm = "FullName"

Set db = CurrentDb
Set tdf = db.TableDefs(sTblNm)
Set fld = tdf.CreateField(sFldNm)

fld.Properties("Expression") = _
"[NameLast] & ("" ""+[Sufx]) & ("", ""+[NameFirst]) & ("" ""+[MidNm])

tdf.Fields.Append fld

MsgBox "Done creating " & sFldNm _
& " in " & sTblNm

Proc_Exit:
On Error Resume Next
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
Exit Sub

Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " CreateCalculatedField: " _
& "field: " & sFldNm & " table: " & sTblNm

Resume Proc_Exit
Resume

End Sub
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access