If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How to create Access 2010 Calculated field using VBA ?
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. |
#2
|
|||
|
|||
How to create Access 2010 Calculated field using VBA ?
"exebat" wrote in message
... 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 |
Thread Tools | |
Display Modes | |
|
|