据我了解,您想通过调用一些函数和过程来创建数据库和其中的对象。我认为最好的方法是使用 DAO 库。下面是 VBScript 示例:
Sub CreateDatabaseFile(ByVal strDbPath)
Dim wspDefault 'As Workspace
Dim dbs ' As Database
Dim dbEngine ' DAO DB Engine
Dim dbLangGeneral
dbLangGeneral = ";LANGID=0x0409;CP=1252;COUNTRY=0"
Set dbEngine = CreateObject("DAO.DBEngine.120")
Set wspDefault = DBEngine.Workspaces(0)
Set dbs = wspDefault.CreateDatabase(strDbPath, dbLangGeneral)
Dim s
s="CREATE TABLE tblCustomers (CustomerID INTEGER CONSTRAINT PK_tblCustomers PRIMARY KEY, " _
& " [Last Name] TEXT(50) NOT NULL, [First Name] TEXT(50) NOT NULL, Phone TEXT(10), Email TEXT(50), " _
& " Address TEXT(40)) "
dbs.execute s
dbs.Close
Dim AccessApp
Set AccessApp = CreateObject("Access.Application")
AccessApp.OpenCurrentDatabase strDbPath
Dim frm 'As Form
Dim ctlLabel 'As Control
Dim ctlText 'As Control
Dim intDataX 'As Integer, intDataY As Integer
Dim intDataY
Dim intLabelX 'As Integer, intLabelY As Integer
Dim intLabelY
' Create new form with tblCustomers table as its record source.
Set frm = AccessApp.CreateForm
'frm.Name = "MyForm"
frm.RecordSource = "tblCustomers"
' Set positioning values for new controls.
intLabelX = 100
intLabelY = 100
intDataX = 1000
intDataY = 100
' Create unbound default-size text box in detail section.
Dim acTextBox
acTextBox = 109
Set ctlText = AccessApp.CreateControl(frm.Name, acTextBox, , "", "", _
intDataX, intDataY)
ctlText.ControlSource = "Last Name"
Dim acLabel
acLabel = 100
' Create child label control for text box.
Set ctlLabel = AccessApp.CreateControl(frm.Name, acLabel, , _
ctlText.Name, "NewLabel", intLabelX, intLabelY)
Dim acButton
AccessApp.DoCmd.Save, frm.Name
' Restore form.
AccessApp.DoCmd.Restore
AccessApp.DoCmd.Quit
End Sub
Call CreateDatabaseFile("c:\test\a test database file.mdb")