By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,500 Members | 830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,500 IT Pros & Developers. It's quick & easy.

adding a field to a table

P: n/a
How do I add a new field to a table. the code below gives a type mismatch
error

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

Set db = CurrentDb
Set rs = db.OpenRecordset("mytable", dbOpenDynaset)

rs.Fields.Append "test", adChar

Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
To append a field to a table, add it to the TableDef, not to a Recordset.

Dim db As DAO.Database
Dim tdf As TableDef
Dim fld As DAO.Field

Set db = CurrentDb()
Set tdf = db.TableDefs("MyTable")
Set fld = tdf.CreateField("MyField, dbText)
tdf.Fields.Append fld

For the field type, make sure you use the DAO constants, not the ADOX
constants.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Earl" <wo*****@mindspring.com> wrote in message
news:ht*********************@news4.srv.hcvlny.cv.n et...
How do I add a new field to a table. the code below gives a type mismatch
error

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

Set db = CurrentDb
Set rs = db.OpenRecordset("mytable", dbOpenDynaset)

rs.Fields.Append "test", adChar

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.