How to add/delete more fields to a table

S

Shirley

Hi,

I am trying to use VB script to add and delete fields to
an existing table. How can I do it?

Appreciate your response very much!

Thanks,

Shirley
 
T

Tim Ferguson

I am trying to use VB script to add and delete fields to
an existing table. How can I do it?

Option Explicit

' this file is to practise DAO from vbscript

Const strMDBFile = "temporary.mdb"

Const c_dbFailOnError = 128

Dim dbe, db
Dim strSQL

' Okay, get access to the database first
Set dbe = CreateObject("DAO.DBEngine.36")
Set db = dbe.OpenDatabase(strMDBFile)

' create the command
strSQL = "ALTER TABLE MyTable " & vbCrLf & _
"ADD COLUMN MyNewColumn INTEGER NULL;"

' run it the usual way
db.Execute strSQL, c_dbFailOnError

' look for errors
If Err.Number <> 0 Then
WScript.Echo "Oops - there was a problem"
' signal the error
WScript.Quit 12

End If

' recover database objects
db.Close

' normal close
WScript.Quit 0


' Hope that helps

' Tim F
 

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