A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to create Access 2010 Calculated field using VBA ?



 
 
Thread Tools Display Modes
  #1  
Old April 21st, 2010, 09:39 AM posted to microsoft.public.access
exebat[_2_]
external usenet poster
 
Posts: 14
Default 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  
Old April 22nd, 2010, 06:32 PM posted to microsoft.public.access
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:24 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.