If i want to add a new column or field in access table .
Here is the code
Sub add_new_column_using_dao()
Dim fld As DAO.Field
Dim rs As DAO.Recordset
' add new field or column name "New_Sales1"
Set fld = CurrentDb.TableDefs("sales_detail").CreateField("New_Sales1", dbLong)
CurrentDb.TableDefs("sales_detail").Fields.Append fld
CurrentDb.TableDefs("sales_detail").Fields.Refresh
RefreshDatabaseWindow
' new_sales1 = sales *100 (multiple each slaes record with 100)
Set rs = CurrentDb.OpenRecordset("sales_detail", dbOpenDynaset)
rs.MoveFirst
Do While Not rs.EOF
rs.Edit
rs.Fields![New_Sales1].Value = rs.Fields![Sales].Value * 100
rs.Update
rs.MoveNext
Loop
rs.Close
End Sub
Download Access Database
No comments:
Post a Comment