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