Connecting Tech Pros Worldwide Help | Site Map

adding a field to a table

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 06:15 PM
Earl
Guest
 
Posts: n/a
Default adding a field to a table

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






  #2  
Old November 12th, 2005, 06:15 PM
Allen Browne
Guest
 
Posts: n/a
Default Re: adding a field to a table

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" <womenfo@mindspring.com> wrote in message
news:htROb.18312$OM2.4130245@news4.srv.hcvlny.cv.n et...[color=blue]
> 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[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.