|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I want to add or delete columns or fields from a table in execution time, i
mean, without editting the table design manually, i think it is maybe possible by code, i would like some help on how to do this. I also want to edit some column properties in excution time, like change its name or its format. thanks |
|
#2
|
|||
|
|||
|
This is possible using VB code. You need to use append and delete methods on the TableDef and Fields collection objects.
|
|
#3
|
|||
|
|||
|
thanks Stev, i´m going to take a look at that, it would be really helpful if you could post an example about this.
thanks again |
|
#4
|
||||
|
||||
|
Here is a short sample:
Dim DBa As Database 'variable declaration Dim TDa As TableDef Set DBa = CurrentDb 'open the database Set TDa = DBa.TableDefs!tblEszkoz1FKarton_Ado01 ' open the TableDef object pointing to the table you wish to modify TDa.Fields.Append TDa.CreateField("FieldName", dbDouble) 'append a field TDa.Fields.Delete "FieldName" 'delete a field See Append or CreateField Help topics for detailed help. BRegs, TBÁrpi |
|
#5
|
||||
|
||||
|
Here is a short sample:
Dim DBa As Database 'variable declaration Dim TDa As TableDef Set DBa = CurrentDb 'open the database '********** I modified the following line because it can be misunderstood because of the table name I used in my earlier message.********** Set TDa = DBa.TableDefs!TableName ' open the TableDef object pointing to the table you wish to modify TDa.Fields.Append TDa.CreateField("FieldName", dbDouble) 'append a field TDa.Fields.Delete "FieldName" 'delete a field See Append or CreateField Help topics for detailed help. BRegs, TBÁrpi |
|
#6
|
|||
|
|||
|
i thank you for helping me, i understand the logic in your example, however, in your variable declaration yo have Database and TableDef as variable types. The question is how to define those types because i´m assuming that they are not already included. Please point me if i'm wrong.
thanks. bye |
|
#7
|
||||
|
||||
|
Use this declaration instead:
Dim DBa As DAO.Database Dim TDa As DAO.TableDef Compile the module. If you receive error message sayimg 'Variable not defined', then you need to check if Microsoft DAO 3.51 Object Library (file: DAO351.OLB) (or 3.6, file is DAO36.OLB) is properly registered. To do this, go to Tools->References... menu path in VBA editor. BRegs, TBÁrpi |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft Access Help > adding columns |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|