Connecting Tech Pros Worldwide Help | Site Map

adding a field to a table

  #1  
Old November 12th, 2005, 07:15 PM
Earl
Guest
 
Posts: 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





  #2  
Old November 12th, 2005, 07:15 PM
Allen Browne
Guest
 
Posts: n/a

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]


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tool to chase down the consequences of adding field to DB tables? sherifffruitfly answers 1 June 27th, 2008 08:06 PM
Adding Field to a Form built on an ODBC Table Andy26 answers 1 April 16th, 2007 12:08 PM
How do I remotely add new field to table in external database? kcopson@hotmail.com answers 4 April 11th, 2007 03:35 PM
way to avoid re-configuring all adapters in a project after adding field to table? Bennett Haselton answers 0 November 18th, 2005 09:04 PM
Add a field to a report after adding field to table? Randy answers 1 November 13th, 2005 10:30 AM