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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
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
SubhasundarCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.