VBA to modify table design

P

Paul Turley

I need to modify a column definition (fom Text (50) to Text (100)) in code.
Against an Acess back-end, I don't think I can use ALTER TABLE so I assume
it must be done in VBA...
 
D

Douglas J. Steele

Actually, you can't do it using VBA. You'll have to add a new field of the
correct size, run an update query to populate the new field, delete the old
field then rename the new field. That's what Access does behind the scenes
when you do this through the GUI. Don't forget to compact your database once
you're done.

On the other hand, you are supposed to be able do this using ALTER TABLE in
newer versions of Access, but I think you need to run the DDL through ADO,
not DAO.
 
A

Allen Browne

Following up on Doug's suggestion, if you use Access 2000 and later, you can
use DDL through ADO to alter the field size.

Example:

Sub ModifyFieldDDL()
Dim strSql As String
strSql = "ALTER TABLE MyTable ALTER COLUMN MyField TEXT(100);"
CurrentProject.Connection.Execute strSql
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top