标题: 不用COPYFILE的方法,如何用代码新建一个空的ACCESS数据库? [打印本页] 作者: zzsim2006 时间: 2007-9-26 10:53 标题: 不用COPYFILE的方法,如何用代码新建一个空的ACCESS数据库? 如题,不用COPYFILE的方法,如何用代码新建一个空的ACCESS数据库?作者: Grant 时间: 2007-9-26 12:01
看看对你有没帮助
Sub Create_AccessProject() '用VBA语句生成Access的MDB数据库 '生成MDB文件
Dim AccessData As Object
Set AccessData = CreateObject("Access.Application")
Dim Stpath As String
Stpath = ThisWorkbook.Path & Application.PathSeparator & "data.mdb" '设定路径
If Dir(Stpath, vbDirectory) = "data.mdb" Then Exit Sub '如date.mdb已存在,则退出
AccessData.NewCurrentDatabase Stpath
Set AccessData = Nothing
'创建表格
Set cnnaccess = CreateObject("Adodb.Connection")
Set rstAnswers = CreateObject("Adodb.Recordset")
cnnaccess.Provider = "Microsoft.Jet.OLEDB.4.0"
Application.Wait Now() + TimeValue("00:00:02") '系统暂停2秒,以等待data.mdb建立成功
cnnaccess.Open "Data Source =" & Stpath & ";Jet OLEDBatabase Password=" & ""
strSQL = "Create Table myData(last_date char(8))"
rstAnswers.Open strSQL, cnnaccess
Set rstAnswers = Nothing
Set cnnaccess = Nothing
End Sub作者: wwwwa 时间: 2007-9-26 14:04
Dim cat As New ADOX.Catalog
cat.Create ""Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\new.mdb""
VCATALOG = Createobject('DAO.DBEngine.36')
VCATALOG.CreateDatabase( "d:\db3.mdb",";LANGID=0x0409;CP=1252;COUNTRY=0")作者: andymark 时间: 2007-9-26 14:36
Dim CatalogX As New ADOX.Catalog
Dim ConnString As String
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test4.mdb"
CatalogX.Create ConnString