how to add fields to already created table at runtime ?

dear experts,
i want to add fields to already created table at runtime.

i am using access as backend & vb as frontend. & i am using DAO for database connectivity.

i.e.
now i have table called "Testing". which has fields like:

sr_no  text  5
name   text 30

now i want to add remark field to "Testing" at runtime how can i add??


please help me with code.

TIA,
Nilesh


AurokripaAsked:
Who is Participating?
 
SubhasundarConnect With a Mentor Commented:
Are you using DAO. If you use DAO ( adding the reference to Microsoft dao 3.51 object library), you can use the following code:
Private Sub AppendTable()
Dim db As DAO.Database
Dim tbf As TableDef
Set db = OpenDatabase("c:\Sample.mdb")'Name of the database
Set tbf = db.TableDefs("Testing")
MsgBox tbf.Name
With tbf
   
    .Fields.Append .CreateField("remark", dbText, 50)
End With

Set tbf = Nothing
Set db = Nothing

End Sub
0
 
TimCotteeCommented:
If you just want this field to exist in your recordset but not add it to the table then the easiest way is to add it in your SQL statement.

SELECT sr_no,name,"" as Testing from <TableName>

This will give you an additional field in your VB recordset but will not add the field to the base table. You can then populate it and use it at will from within VB.

0
 
AurokripaAuthor Commented:
hi Subhasundar ,

Thanks for ur reply. it is working nice & i am satisfly with ur answer.

i hope u will help me in future also when i need.

Thanks,
Nilesh
0
 
SubhasundarCommented:
You're most welcome!!!!
0
All Courses

From novice to tech pro — start learning today.