Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I add a fields in table by using Recordset

Status
Not open for further replies.

nadjib

Programmer
May 14, 2003
23
0
0
CA
Hi everybody,

How can I add a fields in table by using Recordset.

I try to use:

--------------------
Dim db As DAO.Database
Dim rst As Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("Table1")

rst.Fields ????? Append dont work

So what is the object how must used in this case, to permet me to add new field like (string or integer)


cordially
 
You can't do it with a recodset, but you can work with the table Object through DAO or SQL (I assume ADO, too, though I don't use ADO, so I won't speak to that).

DAO:
Sub AddFieldWithDAO()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set db = CurrentDb
Set tdf = db.TableDefs("tblThree")
Set fld = tdf.CreateField("NewField", dbLong)
Call tdf.Fields.Append(fld)
End Sub

SQL:
Sub AddFieldWithSQL()
Dim db As DAO.Database
Dim strSql As String

Set db = CurrentDb
strSql = "ALTER TABLE tblThree ADD COLUMN NewerField text"
Call db.Execute(strSql, dbFailOnError)
End Sub

Hope that's helpful. Check the help files for the commands I used there, and you should see a bunch more on the topic.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Professional Development for Clients Large and Small

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top